Encoding and decoding for every platform

雨燕双飞 提交于 2019-12-13 01:27:58

问题


Encode the string in java then decode on all mobile platform. if i use Base64/AES but they all have different implementation on their platform so How can i encode the string then it will decode on every mobile platform(Android,IOS,Windows,Mozilla,BlackBerry,J2ME phones)


回答1:


As stated in the comments, base64 and AES are sufficiently standardised that every platform will have a compatible implementation.

You just have to ensure a few things:

  • Always use the same character encoding when converting strings to bytes (and vice versa).

  • Use the same AES mode of operation (e.g. CBC-mode) and same padding on all platforms (e.g. PKCS #7 [a.k.a. PKCS #5 in Java]). Don't rely on defaults if you have the option to explicitly state your choice.

  • If you use a mode that requires an IV, ensure this is passed correctly to the destination. For best practice, use a random IV for each message.

  • Use the same key. This may sound silly, but if you are deriving the key from a password, you need to use the same mechanism on every platform. PBKDF2 is a good choice for password-based keys (and you need to use the same hash function and iteration count). If you use fixed keys, ensure you convert from your string representation to the key bytes in a consistent way.



来源:https://stackoverflow.com/questions/25932710/encoding-and-decoding-for-every-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!