java编程下字符串的16位,32位md5加密实现方法
作者:jingxian 时间:2023-07-29 21:34:28
如下所示:
package cn.sunzn.md5;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Str2MD5 {
public static void main(String[] args) {
MD5("sunzn");
}
private static String MD5(String sourceStr) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(sourceStr.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
System.out.println("MD5(" + sourceStr + ",32) = " + result);
System.out.println("MD5(" + sourceStr + ",16) = " + buf.toString().substring(8, 24));
} catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
return result;
}
}
MD5(sunzn,32) = 40379db889f9124819228947faaeb1f7
MD5(sunzn,16) = 89f9124819228947
标签:md5,加密,16位,32位
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现人员信息管理系统
2023-11-02 05:21:31
![](https://img.aspxhome.com/file/2023/5/58425_0s.jpg)
Unity实现粒子光效导出成png序列帧
2023-08-30 21:22:52
美化java代码,从合理注释开始
2022-01-18 16:32:47
C#泛型委托的用法实例分析
2021-09-16 23:29:52
![](https://img.aspxhome.com/file/2023/9/92909_0s.jpg)
使用mybatis-plus的insert方法遇到的问题及解决方法(添加时id值不存在异常)
2023-11-12 19:25:55
![](https://img.aspxhome.com/file/2023/6/59606_0s.png)
Android实现缓存大图到SD卡
2022-07-13 07:13:50
Android ListView和Adapter数据适配器的简单介绍
2023-04-16 04:07:12
![](https://img.aspxhome.com/file/2023/4/97854_0s.png)
详解使用Spring的BeanPostProcessor优雅的实现工厂模式
2023-01-14 02:15:53
C# yield在WCF中的错误用法(一)
2022-06-05 06:36:57
![](https://img.aspxhome.com/file/2023/1/86951_0s.png)
android JSON解析数据 android解析天气预报
2022-01-16 03:33:53
![](https://img.aspxhome.com/file/2023/6/94986_0s.jpg)
Java的MD5工具类和客户端测试类
2022-04-23 03:08:48
ShardingSphere解析SQL示例详解
2023-11-23 13:57:55
Android使用OKhttp3实现登录注册功能+springboot搭建后端的详细过程
2022-07-07 15:07:56
![](https://img.aspxhome.com/file/2023/6/138086_0s.png)
Java用数组实现循环队列的示例
2022-06-26 15:09:48
Java 按行读取文件按行写入文件并以空格分割字符串的方法
2023-08-31 12:32:21
Java实现扑克牌程序
2023-11-11 12:09:52
![](https://img.aspxhome.com/file/2023/0/59340_0s.jpg)
Spring集成jedis的配置与使用简单实例
2023-07-02 04:11:39
IDEA提高开发效率的7个插件(推荐)
2021-10-16 15:28:35
![](https://img.aspxhome.com/file/2023/0/83410_0s.jpg)
详解C#如何实现读写ini文件
2022-02-04 23:15:27
![](https://img.aspxhome.com/file/2023/9/82139_0s.png)
新手Hadoop安装 环境搭建
2022-12-15 05:34:02
![](https://img.aspxhome.com/file/2023/2/74982_0s.jpg)