【发布时间】:2017-07-22 01:41:54
【问题描述】:
我正在使用这个:
import com.sun.org.apache.xml.internal.security.utils.Base64; 编码/解码 Base64 字符串和字节数组以存储到数据库中。
我正在测试编码和解码,看看是否可以取回原始字符串:
SecureRandom srand = new SecureRandom();
byte[] randomSalt = new byte[64];
srand.nextBytes(randomSalt);
System.out.println("rand salt bytes: " + randomSalt); // first line
String salt = Base64.encode(randomSalt);
try {
System.out.println(Base64.decode(salt)); // second line
}catch(Base64DecodingException e){
System.out.println(e);
}
但是,这会打印出来:
rand salt bytes: [B@68286c59
[B@44d01f20
为什么这些不一样,好让我找回原来的字节数组?
【问题讨论】:
标签: java string encoding base64 decoding