我意识到这可能更多是一个普通的java问题,但由于它运行在Notes \ Domino环境中,我以为我会首先检查该社区。java解码base64字符串
摘要:
我似乎不能够字符串解码:dABlAHMAdAA =使用lotus.domino.axis.encoding.Base64或sun.misc.BASE64Decoder
我知道原文是:test
我通过解码确认在http://www5.rptea.com/base64/它看起来是UTF-16。
作为简单的测试,即使用以下:
String s_base64 = "dABlAHMAdAA=";
byte[] byte_base64 = null;
String s_decoded = "";
byte_base64 = new sun.misc.BASE64Decoder().decodeBuffer(s_base64);
s_decoded = new String(byte_base64, "UTF-16");
System.out.println("Test1: " + s_decoded);
byte_base64 = lotus.domino.axis.encoding.Base64.decode(s_base64);
s_decoded = new String(byte_base64, "UTF-16");
System.out.println("Test2: " + s_decoded);
System.out.println("========= FINISH.");
我得到的输出:
测试1:????
Test2:????
如果我创建的字符串为UTF-8
s_decoded = new String(byte_base64, "UTF-8");
它输出:
牛逼
不会引发错误,但它并没有完成代码,不会到达“FINISH” 。
详细
我访问一个ASMX web服务,在SOAP响应,一些节点包含经编码的数据的base64。在这个时候,没有办法改变服务,所以我不得不XPath和解码自己。编码数据是文本或html。如果我通过编码数据通过http://www5.rptea.com/base64/并选择UTF-16,它解码正确,所以我必须做一些不正确的事情。
至于侧面说明,我的编码“测试”:
s_base64 = lotus.domino.axis.encoding.Base64.encode(s_text.getBytes());
System.out.println("test1 encodes to: " + s_base64);
s_base64 = new sun.misc.BASE64Encoder().encode(s_text.getBytes());
System.out.println("test2 encodes to: " + s_base64);
他们都编码为:
dGVzdA == ......这,如果你再送入2个解码器上面,符合市场预期,正确解码。
如果我转到上面的网站,并将“test”编码为UTF-16,则会得到:dABlAHMAdAA =以确认数据是UTF-16。
这就像数据是真正的base64数据,但解码器不能识别它。我现在有点难过。
任何指针或意见将受到感谢。
如果我能跳直通屏幕,给你一个拥抱,我会的。几个小时我一直在徘徊。非常感谢。 –
新的字符串(byte_base64,StandardCharsets.UTF_16LE)可能在Java 7之后 – naveejr