Encryption using AES-128 in Android and IPhone (Different result)

前端 未结 5 621
误落风尘
误落风尘 2020-12-13 21:57

I am trying to encrypt some text using the AES algorithm on both the Android and IPhone platforms. My problem is, even using the same encryption/decryption algorithm (AES-12

5条回答
  •  感动是毒
    2020-12-13 22:23

    It makes me no wonder that you get different results.

    Your problem is that you use misuse a SHA1PRNG for key derivation. AFAIK there is no common standard how a SHA1PRNG work internally. AFAIR even the J2SE and Bouncycaste implementation output different results using the same seed.

    Hence your implementation of your getRawKey(byte[] seed) will generate you a random key. If you use the key for encryption you are getting an result that depends on that key. As the key is random you will not get the same key on iOS and therefore you are getting a different result.

    If you want a key derivation function use a function like PBKDF2 with is nearly fully standardized regarding the key derivation.

提交回复
热议问题