2016-04-29 119 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