当前位置:网站首页>Md5加密方法
Md5加密方法
2022-08-09 15:06:00 【蕾梅黛丝@Remedios0904】
public class Md5Utils
{
private static final Logger log = LoggerFactory.getLogger(Md5Utils.class);
private static byte[] md5(String s)
{
MessageDigest algorithm;
try
{
algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(s.getBytes("UTF-8"));
byte[] messageDigest = algorithm.digest();
return messageDigest;
}
catch (Exception e)
{
log.error("MD5 Error...", e);
}
return null;
}
private static final String toHex(byte hash[])
{
if (hash == null)
{
return null;
}
StringBuffer buf = new StringBuffer(hash.length * 2);
int i;
for (i = 0; i < hash.length; i++)
{
if ((hash[i] & 0xff) < 0x10)
{
buf.append("0");
}
buf.append(Long.toString(hash[i] & 0xff, 16));
}
return buf.toString();
}
public static String hash(String s)
{
try
{
return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
}
catch (Exception e)
{
log.error("not supported charset...{}", e);
return s;
}
}
}边栏推荐
猜你喜欢
随机推荐
Mysql学习(二)
Chapter 4: Using Local Geospatial Data (4.1-4.5)
2022国赛数学建模思路汇总A题B题C题D题 高教社杯
Tracert 命令穿越防火墙不显示星号*的方法
0. About The Author And Preface
kubernetes架构原则和对象设计
认识盒子模型
学编程的第六天
canvas学习(一)
学编程的第八天
动态规划套题:不同路径
第一章:GEE 和 GEEMAP
初学ARM的个人心得
学编程的第十天
低代码的开发前景
Ntdsutil 清除无效的辅域控制器DC
微信小程序学习(二)
uniapp封装全局js并在页面引用
3. Using Earth Engine Data
C语言三大循环while,for,do...while









