【发布时间】:2016-02-15 14:03:07
【问题描述】:
在我的 iOS 应用程序中,我必须解密来自服务器的数据。我使用CommonCrypto框架,经过多次试验,我成功解密了
CCCrypt(kCCDecrypt, // operation
kCCAlgorithmAES128, // Algorithm
kCCOptionPKCS7Padding | kCCModeCBC, // options
key.bytes, // key
key.length, // keylength
nil,// iv
cipherData.bytes, // dataIn
cipherData.length, // dataInLength,
decryptedData.mutableBytes, // dataOut
decryptedData.length, // dataOutAvailable
&outLength); // dataOutMoved
在 java 服务器中,数据被加密
byte[] buff = new byte[100];
byte[] buf2 = new byte[32];
byte[] mainKey = ...
byte[] raw = ...
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new AESEngine());
KeyParameter par = new KeyParameter(mainKey);
int minSize = cipher.getOutputSize(data.length);
byte[] outBuf = new byte[minSize];
int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
int length2 = cipher.doFinal(outBuf, length1);
int actualLength = length1 + length2;
byte[] result = new byte[actualLength];
System.arraycopy(outBuf, 0, result, 0, result.length);
现在,我不明白kCCOptionPKCS7Padding | kCCModeCBC 的含义。 kCCOptionPKCS7Padding = 0x0001 和 kCCModeCBC = 2 所以 kCCOptionPKCS7Padding | kCCModeCBC = 3 但不存在值 3 的分组密码选项。
有没有人可以帮助我理解?
【问题讨论】:
-
“但不存在值为 3 的分组密码的选项” - 这是什么意思?
-
对不起@ArtjomB.,但正如 Rob 向我指出的那样,我误解了位字段的含义。现在更清楚了。
标签: ios aes commoncrypto