Android实现简单MD5加密的方法
作者:与时俱进 时间:2021-10-06 19:51:04
本文实例讲述了Android实现简单MD5加密的方法。分享给大家供大家参考,具体如下:
网上关于android下MD5加密的资料很多,但是测试了下总是跟网站的md5加密不一样, 后来才知道是编码方式不对,于是就自己写了一个。
private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
public static String toHexString(byte[] b) {
//String to byte
StringBuilder sb = new StringBuilder(b.length * 2);
for (int i = 0; i < b.length; i++) {
sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
sb.append(HEX_DIGITS[b[i] & 0x0f]);
}
return sb.toString();
}
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return toHexString(messageDigest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
希望本文所述对大家Android程序设计有所帮助。
标签:Android,MD5加密
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
idea项目的左侧目录没了如何设置
2022-03-21 15:45:43
![](https://img.aspxhome.com/file/2023/1/86801_0s.jpg)
SpringCloud基本Rest微服务工程搭建过程
2023-08-28 16:23:29
![](https://img.aspxhome.com/file/2023/0/63090_0s.png)
Android自定义ActionProvider ToolBar实现Menu小红点
2022-09-09 05:07:30
![](https://img.aspxhome.com/file/2023/9/98649_0s.gif)
java基础的详细了解第三天
2023-10-05 23:47:04
![](https://img.aspxhome.com/file/2023/9/84609_0s.png)
Java SpringBoot在RequestBody中高效的使用枚举参数原理案例详解
2022-03-28 01:47:18
![](https://img.aspxhome.com/file/2023/4/71684_0s.jpg)
Spring一步到位精通拦截器
2022-01-03 18:31:50
![](https://img.aspxhome.com/file/2023/5/68165_0s.png)
mybatis中映射文件(mapper)中的使用规则
2021-06-28 20:09:08
![](https://img.aspxhome.com/file/2023/8/76248_0s.png)
IDEA代码规范插件P3C+代码注释模板配置方法
2022-10-30 17:32:55
![](https://img.aspxhome.com/file/2023/8/86838_0s.png)
OpenTelemetry初识及调用链Trace详解
2021-08-03 12:37:14
![](https://img.aspxhome.com/file/2023/9/85549_0s.png)
C#实现添加多行文本水印到Word文档
2023-03-22 07:45:33
![](https://img.aspxhome.com/file/2023/8/92888_0s.png)
SpringBoot日志框架之Log4j2快速入门与参数详解
2023-11-15 21:17:59
![](https://img.aspxhome.com/file/2023/3/61653_0s.webp)
Java利用自定义注解实现数据校验
2022-12-03 09:56:49
C# 文字代码页 文字编码的代码页名称速查表
2023-12-13 04:03:54
JavaEE微框架Spring Boot深入解读
2021-07-31 14:24:55
![](https://img.aspxhome.com/file/2023/0/83010_0s.png)
关于C# Math 处理奇进偶不进的实现代码
2023-03-25 09:30:29
解析SpringBoot中使用LoadTimeWeaving技术实现AOP功能
2023-04-19 00:21:47
![](https://img.aspxhome.com/file/2023/1/69671_0s.jpg)
一篇文章带你深入了解Java类加载
2023-06-11 22:12:00
![](https://img.aspxhome.com/file/2023/0/66710_0s.png)
利用maven引入第三方jar包以及打包
2023-11-15 04:23:17
![](https://img.aspxhome.com/file/2023/0/59010_0s.jpg)
ToStringBuilder类的一些心得
2022-10-10 04:02:27
C#读写INI文件的方法
2023-12-08 15:31:10