MD5算法-参考网上的资料改写
import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;
public class MD5 {
private MessageDigest __digest = null;
public String ToMD5(String s)
{
try{
__digest=MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e)
{
System.err.println("Failed to load the MD5 MessageDigest. ");
e.printStackTrace();
return null;
}
__digest.update(s.getBytes());
return toHex(__digest.digest());
}
private String toHex(byte[] bytes){
String HEX="0123456789ABCDEF";
String data="";
char a,b;
for (int i = 0; i < bytes.length; i++)
{
a=HEX.charAt((bytes[i] & 0xf0) >> 4);
b=HEX.charAt(bytes[i] & 0x0f);
data=data + a + b;
}
return data;
}
}