我的代码:
private static String convertToBase64(String string)
{
final byte[] encodeBase64 =
org.apache.commons.codec.binary.Base64.encodeBase64(string
.getBytes());
System.out.println(Hex.encodeHexString(encodeBase64));
final byte[] data = string.getBytes();
final String encoded =
javax.xml.bind.DatatypeConverter.printBase64Binary(data);
System.out.println(encoded);
return encoded;
}
现在我调用它:convertToBase64("stackoverflow");
并得到以下结果:
6333526859327476646d56795a6d787664773d3d
c3RhY2tvdmVyZmxvdw==
为什么我得到不同的结果?
最佳答案
我认为 Hex.encodeHexString 会将您的字符串编码为十六进制代码,第二个是普通字符串
关于java - 为什么对 Base64 类的调用会返回不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11360307/