编码和解码为各种平台 [英] Encoding and decoding for every platform

查看:143
本文介绍了编码和解码为各种平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恩code Java中的字符串中的所有移动平台然后去code。
如果我使用Base64编码/ AES但他们都有不同的实现自己的平台上,以便
我怎么能连接code中的字符串,那么它会去code每一个移动平台上(的Andr​​oid,IOS,Windows中,Mozilla的,黑莓,J2ME手机)

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)

推荐答案

由于在评论,说的base64和AES充分标准化,每个平台都会有一个兼容的实现。

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).

使用操作(如CBC模式)和填充相同的同一AES模式在所有平台上(如PKCS#7 [又名PKCS#5用Java])。如果你必须明确地说明你选择的选项不要依赖于默认值。

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.

如果您使用的需要IV模式,确保这是正确传递到目的地。对于最佳做法,使用每个消息随机IV。

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.

使用相同的密钥。这听起来可能很傻,但如果你是从一个密码导出密钥,您需要使用相同的机制每个平台上。 PBKDF2是基于密码的密钥一个不错的选择(你需要使用相同的哈希函数和迭代次数)。如果您使用的固定键,确保你从你的字符串转换重新presentation的关键字节以一致的方式。

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.

这篇关于编码和解码为各种平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆