Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
Import Org.apache.log4j.Logger; /** * MD5 Cryptographic Processing/public class Passworddigester {private static Logger Logger = Logger.getlogger (passwor
Ddigester.class);
private static final String algorithm_md5 = "MD5"; /** * Encrypt the password with MD5 * @param pass the password to encryption * See more highlights of this column: Http://www.bianceng . cnhttp://www.bianceng.cn/programming/java/* @return Encryption String */public static string GetPassMD5 (S
Tring Pass) {String keys = null;
try {messagedigest MD = messagedigest.getinstance (ALGORITHM_MD5);
if (pass = = null) {pass = "";
} byte[] Bpass = pass.getbytes ("UTF-8");
Md.update (Bpass);
Keys = new String (Md.digest (), "GBK");
Keys = bytestohexstring (Md.digest ()); catch (NosuchalgorithMexception aex) {logger.error ("There is no" + algorithm_md5 + "algorithm!");} catch (Java.io.UnsupportedEncodingException Uex) {logger.error ("Can not encode the password-" + uex.getmess
Age ());
return keys; /** * Converts beye[to hexadecimal string * @param barray * @return * * public static final string byte
Stohexstring (byte[] barray) {stringbuffer sb = new StringBuffer (barray.length);
String stemp;
for (int i = 0; i < barray.length i++) {stemp = integer.tohexstring (0xFF & Barray[i]);
if (Stemp.length () < 2) {sb.append (0);
} sb.append (Stemp.touppercase ());
return sb.tostring ();
public static void Main (string[] args) {String a = "qazwsx";
System.out.println (GetPassMD5 (a)); }
}