Hex.java
package org.springframework.security.crypto.codec;
//...
private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
public static char[] encode(byte[] bytes) {
final int nBytes = bytes.length;
char[] result = new char[2 * nBytes]; // 1 hex contains two chars
// hex = [0-f][0-f], e.g 0f or ff
int j = 0;
for (byte aByte : bytes) { // loop byte by byte
// 0xF0 = FFFF 0000
result[j++] = HEX[(0xF0 & aByte) >>> 4]; // get the top 4 bits, first half hex char
// 0x0F = 0000 FFFF
result[j++] = HEX[(0x0F & aByte)]; // get the bottom 4 bits, second half hex char
// combine first and second half, we get a complete hex
}
return result;
}
【 在 PlutoKey 的大作中提到: 】
: md5得到的字节数组byte[],如何转成hex十六进制字符串String?
: md5取摘要,得到了一个128位/16字节的数组 byte[],
: 需要再转换成一个32个字符的十六进制字符串 String。
: ...................
--
FROM 223.104.119.*