import java.security.MessageDigest;
public class Encryptor {
/**
* 用MD5方式加密字符串
* @param source 源字符串
* @return 加密后的字符串
*/
public final static String MD5(String source) {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (Exception e) {
e.printStackTrace();
return "";
}
byte[] byteArray = source.getBytes();
byte[] md5Bytes = md5.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
hexValue.append(String.format("%1$02x", val));
}
return hexValue.toString();
}
}
用MD5方式加密字符串
自己写的一个采用MD5 方式加密字符串类