当前位置:网站首页>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必知必会(二)
【建模必胜秘籍】往届国赛建模方法 2021高教社杯 国赛数学建模
js中的Date对象 及 将时间戳转换为yy-mm-dd hh:mm:ss格式的方法
第一章:GEE 和 GEEMAP
C语言扫雷
看得见风和日丽,看不见风起“云”涌
用指针和malloc定义一个数组
学编程的第五天
2022高教社杯 国赛数学建模 D题思路
超级火的夏日小空调
while read line中执行ssh出现只执行一次
单臂路由与三层交换机实现跨VLAN通讯
Anatomy of Storage Size, Value Range, and Output Format of Basic Data Types in C Language
Lens 创建 Service Accounts 及分配权限
Chapter 3: Use of GEE Data (3.4-3.11)
WinServer 2019 组策略删除本地管理员且只允许域用户登陆
第三章:GEE数据的使用(3.1-3.3)
2. Creating Interactive Maps
Jenkins Pipeline编写思路与技巧
1. Introducing GEE and Geemap