Full version of MD5 Encryption Algorithm in Java, javamd5 Encryption Algorithm
Some data is inevitably encrypted during Java software development. Therefore, Java provides its own MessageDigest to implement text encryption algorithms, the following is an example of the MD5 encryption tool code for text encryption:
Package net. yuerwan. commons. util; import java. security. messageDigest; import java. security. noSuchAlgorithmException; import org. apache. commons. lang. stringUtils;/*** function: MD5 encryption tool class * Description: Reprint Please note: Wenbo small station --- http://www.iwwenbo.com */public class MD5Util {/*** 1. 32-bit lowercase MD5 encryption for text * @ param plainText the text to be encrypted * @ return encrypted content */public static String textToMD5L32 (String plainText) {String result = null; // first determine whether it is null if (StringUtils. isBlank (plainText) {return null;} try {// first instantiate and initialize MessageDigest md = MessageDigest. getInstance ("MD5"); // get the byte array byte [] btInput = plainText in the default byte encoding format of the operating system. getBytes (); // process the byte array. md. update (btInput); // perform hash calculation and return the result byte [] btResult = md. digest (); // The length of the data obtained after hash calculation StringBuffer sb = new StringBuffer (); for (byte B: btResult) {int bt = B & 0xff; if (bt <16) {sb. append (0);} sb. append (Integer. toHexString (bt);} result = sb. toString ();} catch (NoSuchAlgorithmException e) {e. printStackTrace ();} return result;}/*** 2. perform 32-bit MD5 capitalized encryption on the text * @ param plainText the text to be encrypted * @ return encrypted content */public static String textToMD5U32 (String plainText) {if (StringUtils. isBlank (plainText) {return null;} String result = textToMD5L32 (plainText); return result. toUpperCase ();}
Complete reading> Click me;