Copy Code code as follows:
package other;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
/*
* MD5 algorithm
*/
public class MD5 {
Global array
Private final static string[] strdigits = {"0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "B", "C", "D", "E", "F"};
Public MD5 () {
}
//return in the form of numbers and strings
private static string bytetoarraystring (Byte bbyte) {
& nbsp; int iRet = Bbyte;
//System.out.println ("iret=" +iret);
if (IRet < 0) {
IRet + 256;
}
int iD1 = IRET/16;
int iD2 = iRet% 16;
return STRDIGITS[ID1] + STRDIGITS[ID2];
}
//Return form is numeric only
private static String Bytetonum (byte bbyte) {
& nbsp; int iRet = Bbyte;
System.out.println ("iret1=" + iRet);
if (IRet < 0) {
IRet + 256;
}
return string.valueof (IRet);
}
//Convert byte array to 16 binary string
private static String bytetostring (byte[] bbyte) {
StringBuffer sbuffer = new StringBuffer ();
for (int i = 0; i < bbyte.length i++) {
& nbsp; sbuffer.append (bytetoarraystring (bbyte[i));
}
return sbuffer.tostring ();
}
public static string Getmd5code (String strobj) {
String resultstring = null;
try {
resultstring = new String (strobj);
MessageDigest MD = Messagedigest.getinstance ("MD5");
//md.digest () This function returns a byte array that holds the result of a hash value
resultstring = bytetostring (Md.digest ( Strobj.getbytes ()));
} catch (NoSuchAlgorithmException ex) {
Ex.printstacktrace ();
}
return resultstring;
}
public static void Main (string[] args) {
MD5 getMD5 = new MD5 ();
System.out.println (Getmd5.getmd5code ("000000"));
}
}