不同的字符集的Android操作系统版本 [英] Different Charset in Android OS version
问题描述
我写了 AES code
加密和我意识到不同版本的Android 加密
不同。我花了一段时间谷歌和阅读一些关于的getBytes()
都受到系统因此加密
字符串的字符集是不同的。
I am writing an AES code
for encryption and I realized different version of Android encrypt
differently. I took sometime to Google and read something about getBytes()
are subject to the charset in the system therefore the encrypted
String is different.
我的日志的信息Log.i(字符集,Charset.defaultCharset()的toString());
在的Android 2.3 它说:
06-26 16:10:33.954: I/Charset(453): Charset[UTF-8]
的Android 2.2 它说:
06-26 16:05:19.140: I/Charset(737): com.ibm.icu4jni.charset.CharsetICU[UTF-8]
的Android 4.x版说:
06-26 15:53:17.770: I/Charset(16957): java.nio.charset.CharsetICU[UTF-8]
的Android 2.3和4.x加密/解密结果相同的字符串,但2.2是不同
Android 2.3 and 4.x encrypt/decrypt the string with the same result but 2.2 is different.
我可以做的getBytes什么()
,使其对所有版本一致?
What can I do to getBytes()
to make it consistent to all version?
推荐答案
您可以通过编码的getBytes()
。例如:
You can pass encoding to getBytes()
. Example:
String myString = "test";
byte[] bytes = myString.getBytes("UTF-8");
有关支持值的列表,请参阅:
http://developer.android.com/reference/java/nio/charset /Charset.html
For a list of supported values see: http://developer.android.com/reference/java/nio/charset/Charset.html
修改结果
我懂了。但我不明白,为什么不同的Android版本加密的不同。即使它使用不同的库,标准应该是一样的......怪异。也许你可以尝试实现自己的的getBytes()
那么它完全可以在所有版本完全相同。我发现这个例子:http://www.java$c$cgeeks.com/2010/11/java-best-practices-char-to-byte-and.html
EDIT
I see. But I don't understand why different versions of Android encrypt differently. Even it uses different libraries, the standard should be the same...Weird. Maybe you can try to implement your own getBytes()
then it will work exactly same on all versions. I found this example: http://www.javacodegeeks.com/2010/11/java-best-practices-char-to-byte-and.html
这篇关于不同的字符集的Android操作系统版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!