首页 > 其他 > 详细

对明文字符串进行MD5加密

时间:2020-05-04 13:50:30      阅读:54      评论:0      收藏:0      [点我收藏+]

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;
}
结果:

技术分享图片

 

 

技术分享图片

 

对明文字符串进行MD5加密

原文:https://www.cnblogs.com/mc-74120/p/12826188.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!