[英]Decrypt AES128/CBC in Objective-C from PHP
I'm new to xCode and Objective-C. 我是xCode和Objective-C的新手。 I've coded a QR-Scanner, now I need to decrypt the Data which is encryptet with AES128 CBC. 我已经编码了QR扫描仪,现在我需要解密使用AES128 CBC加密的数据。 I encrypt the plaintext using this snippet in php: http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php 我在php中使用此代码段加密了纯文本: http : //www.androidsnippets.com/encrypt-decrypt-between-android-and-php
Could you help me pls? 你能帮我吗? Sorry for my bad English, I'm German :D 对不起,我的英语不好,我是德语:D
Use CommonCrypto, See CommonCrypto and CCCryptor 使用CommonCrypto,请参阅CommonCrypto和CCCryptor
Here is a snippit to get you started: 这是一个摘要,可帮助您入门:
+ (NSData *)doCipher:(NSData *)dataIn
iv:(NSData *)iv
key:(NSData *)symmetricKey
context:(CCOperation)encryptOrDecrypt
error:(NSError **)error
{
CCCryptorStatus ccStatus = kCCSuccess;
size_t cryptBytes = 0; // Number of bytes moved to buffer.
NSMutableData *dataOut = [NSMutableData dataWithLength:dataIn.length + kCCBlockSizeAES128];
ccStatus = CCCrypt( encryptOrDecrypt,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
symmetricKey.bytes,
kCCKeySizeAES128,
iv.bytes,
dataIn.bytes,
dataIn.length,
dataOut.mutableBytes,
dataOut.length,
&cryptBytes);
if (ccStatus == kCCSuccess) {
dataOut.length = cryptBytes;
}
else {
if (error) {
*error = [NSError errorWithDomain:@"kEncryptionError"
code:ccStatus
userInfo:nil];
}
dataOut = nil;
}
return dataOut;
}
Also see RNCryptor for a full implementation. 另请参见RNCryptor以获取完整的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.