The
looks like this:
package cn.sunzn.md5;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
public class Str2md5 {public static void main (string[] args) {MD5 ("SUNZN");
private static string MD5 (String sourcestr) {string result = ' ";
try {messagedigest MD = messagedigest.getinstance ("MD5");
Md.update (Sourcestr.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 <) buf.append ("0");
Buf.append (integer.tohexstring (i));
result = Buf.tostring ();
System.out.println ("MD5 (" + sourcestr +) = "+ result);
System.out.println ("MD5 (" + Sourcestr + ",) =" + buf.tostring (). SUBSTRING (8, 24));
catch (NoSuchAlgorithmException e) {System.out.println (e);
} return result; }
}
MD5 (sunzn,32) = 40379db889f9124819228947faaeb1f7
MD5 (sunzn,16) = 89f9124819228947
The above is a small series for everyone to bring the Java programming string 16 bits, 32-bit MD5 encryption to achieve the full content of the method, I hope to help you, a lot of support cloud Habitat Community ~