// Message Digest: processes an array of characters of any length into an array of characters of a fixed length. It is used to ensure that the original string is not modified. // You can also use the password for confirmation. If the password is the same, the values generated by MD5 must be consistent. Otherwise, different public class datautil {public static void main (string [] ARGs) throws exception {char [] CH = {'0 ', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A ', 'B', 'C', 'D', 'E', 'F',}; string src = "Tang"; stringbuffer sb = new stringbuffer (); byte [] b1 = SRC. getbytes (); system. out. println ("-----------" + b1.length); For (byte B: B1) {system. out. print (B + "");} system. out. println (); messagedigest MD = messagedigest. getinstance ("MD5"); byte [] b2 = md. digest (B1); system. out. println ("-------" + b2.length); For (byte B: B2) {system. out. print (B + ""); // the four-digit sb. append (CH [B> 4 & 0x0f]); // four-bit sb. append (CH [B & 0x0f]);} system. out. println (); system. out. println (sb. length () + ":" + sb. tostring ());}}
MD5 algorithm principle