在我的iOS应用程序中,我必须解密来自服务器的数据。我用CommonCrypto
框架,经过多次试验,我成功地与CCCrypt AES解密
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指出的,我误解了位域的含义。现在更清楚了。 – Giorgio