【问题标题】:Need to do Encryption AES256需要做加密AES256
【发布时间】:2016-08-24 10:27:18
【问题描述】:

如何通过 iso10126padding 和 CBC 模式在 AES 256 中加密 NSDATA,需要像 android 的密码一样。请帮助使用 AES256 加密对 NSData 进行加密。

【问题讨论】:

  • 显示一些代码,你也尝试过什么以及你遇到问题的地方

标签: ios objective-c iphone encryption nsdata


【解决方案1】:

去这个问题它会帮助你:AES Encryption for an NSString on the iPhone

或转到:https://github.com/RNCryptor/RNCryptor

在 Objective-C 中

Obj-C

//
// Encryption
//
NSString *password = @"Secret password";
RNEncryptor *encryptor = [[RNEncryptor alloc] initWithPassword:password];
NSMutableData *ciphertext = [NSMutableData new];

// ... Each time data comes in, update the encryptor and accumulate some ciphertext ...
[ciphertext appendData:[encryptor updateWithData:data]];

// ... When data is done, finish up ...
[ciphertext appendData:[encryptor finalData]];


//
// Decryption
//
RNDecryptor *decryptor = [[RNDecryptor alloc] initWithPassword:password];
NSMutableData *plaintext = [NSMutableData new];

// ... Each time data comes in, update the decryptor and accumulate some plaintext ...
NSError *error = nil;
NSData *partialPlaintext = [decryptor updateWithData:data error:&error];
if (error != nil) {
    NSLog(@"FAILED DECRYPT: %@", error);
    return;
}
[plaintext appendData:partialPlaintext];

// ... When data is done, finish up ...
NSError *error = nil;
NSData *partialPlaintext = [decryptor finalDataAndReturnError:&error];
if (error != nil) {
    NSLog(@"FAILED DECRYPT: %@", error);
    return;
}

[ciphertext appendData:partialPlaintext];

【讨论】:

  • 在目标 c 中我如何使用 RNCryptor/RNCryptor
  • 检查更新的答案,更多开放的 Github 链接,您可以获得所有详细信息
  • 问题在于使用起始向量和密钥
【解决方案2】:

您可以将属性设置为 Transformable 并使用您自己的 Transformer 类来应用加密/解密。

这是可转换属性的指南: enter link description here

【讨论】:

  • 可转换属性的任何有用代码,因为我需要 iso10126 填充和 CBC 模式,我认为 comoncrpto 没有相同的库。
猜你喜欢
  • 1970-01-01
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 2019-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多