Hellp所有
我在iOS和安卓中使用了RNCryptor/JNCryptor,下面是iOS中用于加密和解密的代码。
Android中的加密代码
public static String EncryptMessage(String message)
{
JNCryptor cryptor = new AES256JNCryptor();
byte[] plaintext = message.getBytes();
byte[] ciphertext = null;
try {
ciphertext = cryptor.encryptData(plaintext,Constants.ENCRYPTION_KEY.toCharArray());
} catch (CryptorException e) {
// Something went wrong
e.printStackTrace();
}
return Base64.encodeBytes(ciphertext);
}iOS中的解密码
NSData *fromAData = [@"AwEche05IIj/OYEN5brgF/p6jyfKfARJliUQwEwa2lko40+ScPMumlDSIZWB2O6XRZjIucXVbggieWaHb2x6sJkYYt7tn3k17V5Jd5PAnkIoFA==" base64DecodedData];
NSData *fromADecryptedData = [RNDecryptor decryptData:fromAData withSettings:kRNCryptorAES256Settings password:@"password" error:&decryptionError];
NSLog(@"decryptionError %@", decryptionError);
NSLog(@"Result = %@", fromPHPDecryptedData);
NSLog(@"Result = %@", [[NSString alloc] initWithData:fromADecryptedData encoding:NSUTF8StringEncoding]);我也尝试过用密码进行简单解密。
NSData *fromADecryptedData = [RNDecryptor decryptData:fromAData withPassword:@"password" error:&decryptionError];获取未知标头的错误,错误code=2
我使用相同的刺“密码”作为密码在两边。
如果有人知道,请告诉我,如果我错过了什么。
发布于 2014-11-13 06:19:41
一旦我在iOS中更新了我的iOS库.
我的iOS RNcryptor库版本是v2.2
Android版本1.2.0
https://stackoverflow.com/questions/26902377
复制相似问题