Java MD5 encryption tool class, javamd5 tool class
Import java. security. messageDigest;/*** MD5 encryption tool class * @ author zwq */public class MD5Util {/*** MD5 encryption ** @ param message the information to be encrypted, for example: 123456 * @ return returns the MD5 encrypted 32-bit uppercase String, for example, E10ADC3949BA59ABBE56E057F20F883E */public static String encode (String message) throws Exception {String md5 = ""; messageDigest md = MessageDigest. getInstance ("MD5"); // create an md5 Algorithm object byte [] messageByte = message. getBytes ("UTF-8"); byte [] md5Byte = md. digest (messageByte); // obtain the MD5 byte array, 16*8 = 128-bit md5 = bytesToHex (md5Byte); // convert it to a hexadecimal string return md5 ;} /*** convert the byte array to a hexadecimal string * @ param bytes the byte array to be converted, for example, [-, 10,-, 73,-, 89, -85,-15,-] * @ return returns the converted uppercase String, for example, bytes */public static String bytesToHex (byte [] bytes) {StringBuffer hexStr = new StringBuffer (); int num; for (int I = 0; I <bytes. length; I ++) {num = bytes [I]; if (num <0) {num + = 256;} if (num <16) {hexStr. append ("0");} hexStr. append (Integer. toHexString (num);} return hexStr. toString (). toUpperCase ();}}