The code is as follows
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
public class Main {
public static void Main (string[] args) {
Main main = new main ();
System.out.println (Main.encryption ("xiaowen123"));
}
/**
*
* @param plaintext
* Clear Text
* @return 32-bit ciphertext
*/
public string encryption (string plaintext) {
String md5 = new string ();
try {
MessageDigest MD = messagedigest.getinstance ("MD5");
Md.update (Plaintext.getbytes ());
byte b[] = Md.digest ();
int i;
StringBuffer buf = new StringBuffer ("");
for (int offset = 0; offset < b.length; offset++) {
i = B[offset];
if (I < 0)
i + = 256;
if (I < 16)
Buf.append ("0");
Buf.append (integer.tohexstring (i));
}
MD5 = buf.tostring ();
} catch (NoSuchAlgorithmException e) {
E.printstacktrace ();
}
return MD5;
}
}
Detailed Description: http://java.662p.com/thread-3792-1-1.html
This article is from the "Java" blog, so be sure to keep this source http://6058287.blog.51cto.com/6048287/1579859
JAVA32 bit MD5 encryption