如何通过iso10126padding和CBC模式加密AES 256中的NSDATA,需要像android的密码那样做。请帮助用AES256加密对NSData进行加密。
答案 0 :(得分:0)
转到这个问题它会对你有所帮助: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];
答案 1 :(得分:0)
您可以将属性设置为Transformable并使用您自己的Transformer类来应用加密/解密。
这是可转换属性的指南: enter link description here