2016-04-29 125 views
-1

如何通过iso10126padding和CBC模式加密AES 256中的NSDATA,需要像android的密码那样做。请帮助用AES256加密来做NSData的加密。需要加密AES256

+0

显示一些代码,你也尝试了什么,你在哪里得到的问题 – 2016-04-29 10:12:22

回答

0

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

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

在Objective-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]; 
+0

在Objective C中,如何使用RNCryptor/RNCryptor – Abhimanyu

+0

检查更新的答案,更加开放Github链接,你可以得到所有的细节 – 2016-04-29 10:08:17

+0

问题是使用启动向量和密钥 – Abhimanyu

0

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

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

+0

任何有用的代码Transformable属性,因为我需要iso10126填充和CBC模式,我认为comoncrpto doest没有相同的库。 – Abhimanyu