直接提供方法,参数是需要加密的字符串,返回加密后的结果
public static String md5(String source) {
if (source == null || source.length() == 0) {
throw new RuntimeException(CrowdConstant.MESSAGE_STRING_INVALIDATe);
}
// 1.获取MessageDigest 对象
String algorithm = "md5";
try {
MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
// 2.获取文字符对应的字符数组
byte[] input = source.getBytes();
// 3.执行加密
byte[] digest = messageDigest.digest(input);
// 4.创建BigInteger
int signum = 1;
BigInteger bigInteger = new BigInteger(signum, digest);
// 5.按照16进制将bigInteger转成16进制
int radix = 16;
String encode = bigInteger.toString(radix);
return encode;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return source;
}
1万+

被折叠的 条评论
为什么被折叠?



