String.getBytes(QUOT; UTF-32")返回在JVM和Dalvik虚拟机不同的结果 [英] String.getBytes("UTF-32") returns different results on JVM and Dalvik VM
问题描述
我有一个48字符 AES-192
我使用解密加密数据库的加密密钥。
I have a 48 character AES-192
encryption key which I'm using to decrypt an encrypted database.
然而,它告诉我的密钥长度是无效的,所以我登录的getBytes的结果()。
However, it tells me the key length is invalid, so I logged the results of getBytes().
当我执行:
final String string = "346a23652a46392b4d73257c67317e352e3372482177652c";
final byte[] utf32Bytes = string.getBytes("UTF-32");
System.out.println(utf32Bytes.length);
在我的Mac(Java虚拟机)使用BlueJ的,我得到 192
作为输出。
然而,当我使用:
Log.d(C.TAG, "Key Length: " + String.valueOf("346a23652a46392b4d73257c67317e352e3372482177652c".getBytes("UTF-32").length));
我得到 196
作为输出。
有谁知道为什么发生这种情况,并在Dalvik的是从得到额外的4个字节?
Does anybody know why this is happening, and where Dalvik is getting an additional 4 bytes from?
推荐答案
您应该在两台机器上指定字节序
You should specify endianess on both machines
final byte[] utf32Bytes = string.getBytes("UTF-32BE");
注意UTF-32BE
是一个不同的编码,而不是特殊的 .getBytes
参数。它有固定的字节序,并不需要BOM。更多信息:<一href=\"http://www.uni$c$c.org/faq/utf_bom.html#gen6\">http://www.uni$c$c.org/faq/utf_bom.html#gen6
Note that "UTF-32BE"
is a different encoding, not special .getBytes
parameter. It has fixed endianess and doesn't need BOM. More info: http://www.unicode.org/faq/utf_bom.html#gen6
这篇关于String.getBytes(QUOT; UTF-32&QUOT;)返回在JVM和Dalvik虚拟机不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!