public static void main(String[] args) throws Exception {
String str = "resource";
System.out.println(Arrays.toString(getHash(str,"MD5").getBytes()));//使用默认解码后输出
}
public static String getHash(String str, String hashType) {
try {
MessageDigest digest = MessageDigest.getInstance(hashType);
digest.reset();
byte[] b = digest.digest(str.getBytes());
System.out.println(Arrays.toString(b)); //编码前输出
return new String(b); //使用默认编码
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return str;
}
输出:
[-106, -85, 78, 22, 63, 78, -32, 58, -86, 77, 16, 81, -86, 81, -46, 4]
[-17, -65, -67, -17, -65, -67, 78, 22, 63, 78, -17, -65, -67, 58, -17, -65, -67, 77, 16, 81, -17, -65, -67, 81, -17, -65, -67, 4]
为什么编码前和编码后再解码所输出的不一样?
开满天机
相关分类