1 Public classStringToMD5 {2 3 Private StaticStringBuffer Sbuffer;4 5 Public Staticstring Getmd5code (String str) {6 MessageDigest MD;7 Try {8 //md.digest () The function returns a byte array that holds the result of the hash value9MD = Messagedigest.getinstance ("MD5");Ten byte[] Md5bytes =md.digest (Str.getbytes ()); OneSbuffer =NewStringBuffer (); A for(inti = 0; i < md5bytes.length; i++) { - intval = ((int) Md5bytes[i]) & 0xFF; - if(Val < 16) theSbuffer.append ("0"); - Sbuffer.append (Integer.tohexstring (Val)); - } - returnsbuffer.tostring (); +}Catch(nosuchalgorithmexception e) { - e.printstacktrace (); + } A return""; at } -}
For these are not very understanding of the system (class is not serious), I am afraid to write misleading everyone, think of a half-day write a half-day or delete, know what meaning is unable to express, the method is so, the specific meaning why only to ask a master
MD5 Encryption--java Code