ios - 从 PHP 解密 Objective-C 中的 AES128/CBC
<p><p>我是 xCode 和 Objective-C 的新手。我已经编写了一个 QR 扫描仪,现在我需要解密使用 AES128 CBC 加密的数据。我在 php 中使用此代码段加密明文:<a href="http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php" rel="noreferrer noopener nofollow">http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php</a> </p>
<p>你能帮我吗?对不起我的英语不好,我是德国人:D</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用 CommonCrypto,见 <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/Common%20Crypto.3cc.html#//apple_ref/doc/man/3cc/CommonCrypto" rel="noreferrer noopener nofollow">CommonCrypto</a>和 <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/CCCryptor.3cc.html#//apple_ref/doc/man/3cc/CCCryptor" rel="noreferrer noopener nofollow">CCCryptor</a> </p>
<p>这里有一个片段可以帮助您入门:</p>
<pre><code>+ (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 = ;
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;
}
</code></pre>
<p>另见 <a href="https://github.com/RNCryptor/RNCryptor" rel="noreferrer noopener nofollow">RNCryptor</a>全面实现。</p></p>
<p style="font-size: 20px;">关于ios - 从 PHP 解密 Objective-C 中的 AES128/CBC,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23744348/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23744348/
</a>
</p>
页:
[1]