标签:return hal catch digest exception ima code 字节数组 mic
public static String md5(String resource) {
// 1.判断resource是否有效
if(resource.length()==0||resource==null){
//2.抛出异常
throw new RuntimeException(CrowdConstant.MESSAGE_STRING_INVALIDATE);
}
try {
// 3.获取MessageDigest对象
String way="md5";
MessageDigest messageDigest= MessageDigest.getInstance(way);
//获取资源对应的字节数组
byte[] bytes=resource.getBytes();
//执行加密
byte[] output= messageDigest.digest(bytes);
//创建bigInteger对象
int sginnum=1;
BigInteger bigInteger=new BigInteger(sginnum,output);
//按照16进制将BigInteger对象转化成字符串
int radix=16;
String code=bigInteger.toString(radix);
return code;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
结果:
标签:return hal catch digest exception ima code 字节数组 mic
原文地址:https://www.cnblogs.com/mc-74120/p/12826188.html