public class MD5 {
public static void main(String[] args) {
String md5 = getMD5("210534");
System.out.println(md5);
System.out.println(md5.length());
String encrypt = encrypt("210534");
System.out.println(encrypt);
System.out.println(encrypt.length());
}
// private static final String slat = "&%5123***&&%%$$#@";
/**
* 生成md5
* @param
* @return
*/
public static String getMD5(String str) {
// String base = str +"/"+slat;
String base = str ;
String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
return md5;
}
public static String encrypt(String dataStr) {
try {
// dataStr = dataStr ;
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte s[] = m.digest();
String result = "";
for (int i = 0; i < s.length; i++) {
result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
JAVA生成MD5的方法
最新推荐文章于 2024-09-11 16:36:24 发布