MD5 is message-digest algorithm 5 (Information-Digest algorithm 5): Method One: Add Jar package: ${spring_home}/lib/jakarta-commons/commons-codec.jarimport Org.apache.commons.codec.digest.digestutils;public class Md5util {//returns MD5 encrypted string public static strings MD5 (string Message) {String md5digest = digestutils.md5hex (message); return md5digest;}} Method Two://JDK from the import java.security.messagedigest;//is also the JDK comes with, you can view its source code import sun.misc.BASE64Encoder in OpenJDK; public class Md5util {//returns MD5 after the encrypted string public-static string MD5 (String message) {try {messagedigest MD = Messagedigest.getin Stance ("MD5"); byte[] md5bytes = Md.digest ();//Use BASE64 encoding to convert a sequence of bytes into plaintext base64encoder Base64encoder = new Base64encoder (); Return Base64encoder.encode (md5bytes);} catch (Exception e) {throw new RuntimeException (e);}}} Add: Base64 Encoding principle: Convert 3 bytes to 4 bytes ((3X8) =24= (4X6)) read in 3 bytes, each read a byte, left 8 bits, and then right four times, 6 bits each time, so there is 4 bytes. Decoding principle: Convert 4 bytes to 3 bytes read into 4 6 bits (with or operations), each shift left 6 bits, and then right 3 times, 8 bits each time, so it is restored. Description: 1,BASE64 encoding can be used to pass long identification information in an HTTP environment 2,BASE64 encoded identity information length of 243, 3 bytes to 4 bytes, each byte represents the minimum and maximum number is: 00000000 ~ 001111110~ 63 A total of 64 integers,To call it Base64, it is actually a code table, each number corresponds to a visible character
MD5 Encryption and BASE64 encoding