Importjava.security.MessageDigest;Importjava.security.NoSuchAlgorithmException;/** MD5 Algorithm*/ Public classMD5 {//Global Array Private Final StaticString[] strdigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D", "E", "F" }; PublicMD5 () {}//returns the form of a number followed by a string Private StaticString bytetoarraystring (bytebbyte) { intIRet =Bbyte; //System.out.println ("iret=" +iret); if(IRet < 0) {IRet+ = 256; } intID1 = IRET/16; intiD2 = iRet% 16; returnSTRDIGITS[ID1] +Strdigits[id2]; } //return form is only numeric Private StaticString Bytetonum (bytebbyte) { intIRet =Bbyte; System.out.println ("Iret1=" +IRet); if(IRet < 0) {IRet+ = 256; } returnstring.valueof (IRet); } //convert byte array to 16 binary string Private StaticString bytetostring (byte[] bbyte) {StringBuffer Sbuffer=NewStringBuffer (); for(inti = 0; i < bbyte.length; i++) {sbuffer.append (bytetoarraystring (bbyte[i)); } returnsbuffer.tostring (); } Public Staticstring Getmd5code (String strobj) {string resultstring=NULL; Try{resultstring=NewString (strobj); MessageDigest MD= Messagedigest.getinstance ("MD5"); //md.digest () The function returns a byte array that holds the result of the hash valueResultstring =bytetostring (Md.digest (Strobj.getbytes ())); } Catch(NoSuchAlgorithmException ex) {ex.printstacktrace (); } returnresultstring; } Public Static voidMain (string[] args) {MD5 getMD5=NewMD5 (); System.out.println (Getmd5.getmd5code ("000000")); }}
Go Java implementation of MD5 encryption algorithm