Import java.io.UnsupportedEncodingException;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
public class MD5 {
public static void Main (string[] args) {
try {
System.out.println (Getmd5encryptedpwd ("Kakakakakakakakkakaklalalalala"));
} catch (Exception e) {
}
}
/**
* Converts the specified byte array to a 16 binary string
* @param b
* @return
*/
private static String Bytetohexstr (byte[] b) {
StringBuffer hexstring = new StringBuffer ();
for (int i = 0; i < b.length; i++) {
String hex = integer.tohexstring (B[i] & 0xFF);
if (hex.length () = = 1) {
Hex = ' 0 ' + hex;
}
Hexstring.append (Hex.touppercase ());
}
return hexstring.tostring ();
}
/**
* Get encrypted 16 binary form string
* @param password
* @return
* @throws nosuchalgorithmexception
* @throws unsupportedencodingexception
*/
private static string Getmd5encryptedpwd (string password) throws NoSuchAlgorithmException,
unsupportedencodingexception {
if (password = = NULL | | Password.trim (). Length () = = 0) {
Return "";
}
Declaring Message digest objects
MessageDigest MD = messagedigest.getinstance ("MD5");
Pass the password data to the message digest object
Md.update (Password.getbytes ("UTF-8"));
A byte array to get the message digest
Byte[] Digest = Md.digest ();
Converts a password encrypted in byte array format to a password in 16-string format
Return Bytetohexstr (Digest);
}
}
Java implementation MD5