MD5帮助类
发布日期:2022-01-11 03:09:51
浏览次数:3
分类:技术文章
本文共 1480 字,大约阅读时间需要 4 分钟。
import java.security.MessageDigest;public class MD5Util { /** * 转换字节数组为16进制字串 * @param b 字节数组 * @return 16进制字串 */ public static String byteArrayToHexString(byte b[]) { StringBuffer resultSb = new StringBuffer(); for (int i = 0; i < b.length; i++) resultSb.append(byteToHexString(b[i])); return resultSb.toString(); } /** * 转换byte到16进制 * @param b 要转换的byte * @return 16进制格式 */ public static String byteToHexString(byte b) { int n = b; if (n < 0) n += 256; int d1 = n / 16; int d2 = n % 16; return hexDigits[d1] + hexDigits[d2]; } public static String MD5Encode(String origin, String charsetname) { String resultString = null; try { resultString = new String(origin); MessageDigest md = MessageDigest.getInstance("MD5"); if (charsetname == null || "".equals(charsetname)) resultString = byteArrayToHexString(md.digest(resultString .getBytes())); else resultString = byteArrayToHexString(md.digest(resultString .getBytes(charsetname))); } catch (Exception exception) { } return resultString; } private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; }
转载地址:https://yuki-ho.blog.csdn.net/article/details/52297191 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月12日 09时34分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
webpack入门介绍(三) ---plugins
2019-04-26
关于 Git 的基础知识可能你还不知道
2019-04-26
mysql-基础
2019-04-26
python3-basic
2019-04-26
测试方法(1)
2019-04-26
python3-django
2019-04-26
功能测试(1)
2019-04-26
安全性测试(1)
2019-04-26
html基础
2019-04-26
vi—终端中的编辑器
2019-04-26
Linux
2019-04-26
jmeter-性能测试基础
2019-04-26
unittest
2019-04-26
错误推断法-维护中
2019-04-26
AJAX教程
2019-04-26
git基础
2019-04-26
git基础-01
2019-04-26
mysql-总结
2019-04-26
IPv4地址
2019-04-26
正则表达式
2019-04-26