Java获取字符串Md5值
发布日期:2021-07-01 06:11:20 浏览次数:2 分类:技术文章

本文共 930 字,大约阅读时间需要 3 分钟。

package org.example;import java.io.UnsupportedEncodingException;import java.nio.charset.StandardCharsets;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;public class MD5Test {
public static String getMd5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] bytes = md5.digest(text.getBytes(StandardCharsets.UTF_8)); StringBuilder builder = new StringBuilder(); for (byte aByte : bytes) {
builder.append(Integer.toHexString((0x000000FF & aByte) | 0xFFFFFF00).substring(6)); } return builder.toString(); } public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String str = "hello md5 你好"; System.out.println(getMd5(str)); // fca0127f57c8528791332645b8105bd8 }}

转载地址:https://pengshiyu.blog.csdn.net/article/details/106753684 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:CDN方式使用ElementUI的Message组件
下一篇:Mac环境IDEA编写XML行注释不显示在行首

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年05月06日 22时54分23秒