byte[] input = {0xA,0xB,0xC,0xD};
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(input);
for(int i=0; i<digest.length; i++) {
System.out.format("%x",digest[i]&0xff);
}
我知道如何使用文本字符串获取哈希值,但我没有为此输入获取正确的摘要。正确的是: SHA256(0xABCD)= 123d4c7ef2d1600a1b3a0f6addc60a10f05a3495c9409f2ecbf4cc095d000a6b
答案 0 :(得分:-2)
byte[] input = {(byte)0xAB,(byte)0xCD};
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(input);
for (int i=0; i < digest.length; i++) {
sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println(sb.toString());