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 form is numeric with string private static string bytetoarraystring (byte bbyte) {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 only for the number private static String Bytetonum (byte bbyte) {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 &lT Bbyte.length; i++) {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 () The function returns a byte array that holds the result of the 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")); }}
Java implementation of MD5 encryption algorithm