Java files
Https://pan.baidu.com/s/1kXcif35 Password: 3cjd
Code Case:
Package cn.itcast.estore.utils;
Import Java.math.BigInteger;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
public class Md5utils {
/**
* Encryption using MD5 algorithm
*/
public static string MD5 (string plaintext) {
byte[] secretbytes = null;
try {
Secretbytes = messagedigest.getinstance ("MD5"). Digest (
Plaintext.getbytes ());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException ("No MD5 this algorithm!") ");
}
String Md5code = new BigInteger (1, secretbytes). toString (16);//16 binary digits
If the generated number is below 32 bits, the preceding 0 is required
for (int i = 0; i < 32-md5code.length (); i++) {
Md5code = "0" + md5code;
}
return md5code;
}
public static void Main (string[] args) {
SYSTEM.OUT.PRINTLN (MD5 ("123"));
}
}
MD5 Encryption in Java