【发布时间】:2014-07-24 09:15:02
【问题描述】:
我需要在 MD5 哈希中转换字符串。
我正在使用
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(bytesOfMessage);
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex( byte[] bytes )
{
char[] hexChars = new char[ bytes.length * 2 ];
for( int j = 0; j < bytes.length; j++ )
{
int v = bytes[ j ] & 0xFF;
hexChars[ j * 2 ] = hexArray[ v >>> 4 ];
hexChars[ j * 2 + 1 ] = hexArray[ v & 0x0F ];
}
return new String( hexChars );
}
它正在像这个网站http://www.md5.cz/提供输出
但我需要生成哈希,因为 http://webcodertools.com/hashstring 给出输出。
请在两个站点中使用 test。
通过使用上述功能,我得到了像第一个站点一样的 o/p,但我需要第二个站点提供。
有什么不同的功能还是我错过了什么?
谢谢。
【问题讨论】:
标签: java android encryption md5