Package Com.soufun.com;import Java.io.unsupportedencodingexception;import Java.security.messagedigest;import java.security.nosuchalgorithmexception;/** * @author WHD Data August 13, 2015 */public class Md5test {//MD5 one-way encrypted public static void Main (string[] args) throws nosuchalgorithmexception,unsupportedencodingexception {String str = "HELLOMD digest algorithm Start"; System.out.println ("original value" + str); SYSTEM.OUT.PRINTLN ("Encrypted" + MD5TEST.AFTERMD5 (str)); String digest = MD5TEST.AFTERMD5 (str); System.out.println (Digest.equals (MD5TEST.AFTERMD5 (str))); public static string afterMD5 (String str) throws Nosuchalgorithmexception,unsupportedencodingexception {//Gets MD5 encrypted object, You can also get the SHA encryption object MessageDigest MD5 = messagedigest.getinstance ("MD5"), or//To get the input information using the specified encoding method to obtain the byte byte[] bytes = Str.getbytes (" UTF-8 ");//Use the MD5 class to obtain the digest, which is the encrypted byte md5.update (bytes); byte[] Md5encode = Md5.digest (); StringBuffer buffer = new StringBuffer (), for (int i = 0; i < md5encode.length; i++) {//Use &0xff less than 24 high because it only accounts for 8 low int val = ((int) md5encode[i]) & 0xFf;if (Val <) {Buffer.append ("0");} Returns a string representation of an integer parameter as a 16-based (radix 16) unsigned integer. Buffer.append (Integer.tohexstring (Val));} return buffer.tostring ();}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MD5 Summary Algorithm Example