Android JNI string encryption/decryption

后端 未结 2 1110
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 02:22

I am trying to do aes encryption/decryption in native code C. Encryption does work but when I try to decrypt the string. It doesn\'t end up as original string. Here is the JNI m

相关标签:
2条回答
  • 2021-01-22 03:09

    You are using the low level encryption modes of OpenSSL. Your troubles are likely to vanish if you use the higher level EVP_* methods, e.g. for AES/CBC mode encryption. See also this related question.

    0 讨论(0)
  • 2021-01-22 03:13

    You provide a key that is 72 bits long (9 characters x 8 bits). But it needs to be 128 bit longs (as you specify in the call to AES_set_encrypt_key). Thus the missing 56 bits will be more or less random (depending on what's next to the ukey array).

    To fix it, specified a longer key or fill the remaining bytes with 0s.

    0 讨论(0)
提交回复
热议问题