【发布时间】:2016-08-24 10:27:18
【问题描述】:
如何通过 iso10126padding 和 CBC 模式在 AES 256 中加密 NSDATA,需要像 android 的密码一样。请帮助使用 AES256 加密对 NSData 进行加密。
【问题讨论】:
-
显示一些代码,你也尝试过什么以及你遇到问题的地方
标签: ios objective-c iphone encryption nsdata
如何通过 iso10126padding 和 CBC 模式在 AES 256 中加密 NSDATA,需要像 android 的密码一样。请帮助使用 AES256 加密对 NSData 进行加密。
【问题讨论】:
标签: ios objective-c iphone encryption nsdata
去这个问题它会帮助你: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];
【讨论】:
您可以将属性设置为 Transformable 并使用您自己的 Transformer 类来应用加密/解密。
这是可转换属性的指南: enter link description here
【讨论】: