Packagecom.rick.utils;Importjava.security.MessageDigest;Importjava.security.NoSuchAlgorithmException;/***-------------------------------------------* title:md5util * DESCRIPTION:MD5 encryption algorithm * Create on:2017 April 5 a.m. 9: 53:42 * Copyright (C) strongunion *@authorRICK * Revision history: * Modified Person Modification Date Description *-------------------------------------------*/ Public classMd5util {//Global Array Private Final StaticString[] strdigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "B", "C", "D", "E", "F" }; PublicMd5util () {}//returns the form of a number followed by a string Private StaticString bytetoarraystring (bytebbyte) { intIRet =Bbyte; 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) {md5util getMD5=NewMd5util (); System.out.println (Getmd5.getmd5code ("123456")); }}
170405. Java Edition MD5 tool class