MD5加密算法经典

package cn.com.huawei.opensource.common.https.utils;

import java.security.MessageDigest;

public class MD5Util {
/**
* MD5加密的方法的应用
* @param crb
* @return
*/
public static String MD5Encrypt(String crb) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(crb.getBytes());
return byteToString(digest);
} catch (Exception e) {
e.fillInStackTrace();
}
return null;
}

public static String byteToString(byte[] digest) {
StringBuffer str = new StringBuffer();
String tempStr = "";
for (int i = 0; i < digest.length; i++) {
tempStr = (Integer.toHexString(digest[i] & 0xff));
if (tempStr.length() == 1) {
str.append("0").append(tempStr);
} else {
str.append(tempStr);
}
}
return str.toString().toUpperCase();

}
}

你可能感兴趣的:(算法,Security,OpenSource)