Import Java. security. messagedigest; import Java. security. nosuchalgorithmexception; 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 a number and 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];} // The return format is only 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 the byte array to a hexadecimal string Private Static string bytetostring (byte [] bbyte) {stringbuffer sbuffer = new stringbuffer (); for (INT I = 0; I <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 return value of this function is the byte array resultstring = bytetostring (MD. digest (strobj. getbytes ();} catch (nosuchalgorithmexception ex) {ex. printstacktrace ();} return resultstring;} public static void main (string [] ARGs) {system. out. println (md5.getmd5code ("123456 "));}}