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

前端 未结 5 614
误落风尘
误落风尘 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:24

    On Android, you are using getBytes(). This is an error as it means you are using the default charset rather than a known charset. Use getBytes("UTF-8") instead so you know exactly what bytes you are going to get.

    I don't know the equivalent for Objective-C, but don't rely on the default. Explicitly specify UTF-8 when converting strings to bytes. That way you will get the same bytes on both sides.

    I also note that you are using MD5 in the Objective-C code but not in the Android code. Is this deliberate?

提交回复
热议问题