Decrypting data that was AES encrypted with Objective-C with Java

前端 未结 3 762
没有蜡笔的小新
没有蜡笔的小新 2021-02-03 15:25

I try to decrypt data that was originally encrypted with Objective-C in Java.

There are other questions mentioning this but they are really cluttered and many of them a

3条回答
  •  甜味超标
    2021-02-03 16:14

    1. I would not assume that CCCrypt supported using the same array for input and output. Try using two different arrays.
    2. You have to resize the output array yourself (numBytesEncrypted should be equal to 16 after the call).
    3. As far as I can see, a null IV signals using ECB-encryption instead of CBC. As long as your input is smaller than 15 bytes, it should not make any difference, but it is still something you should fix.

    EDIT: Another issue:

    1. You are using a 24-byte key. AES-128 needs a 128-bit = 16-byte key, AES-192 needs a 192-bit = 24-byte key and AES-256 needs a 256-bit = 32-byte key. You are explicitly indicating AES-128 to CCCrypt, which means it ignores the last 8 bytes of the key. You are just indicating AES to Java, which means it looks at the key-size to decide which AES variant to use. Since you are providing a 24-byte key, it uses AES-192. Fix it so both ends uses the same algorithm and you should be good.

提交回复
热议问题