前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >利用java自带的MD5加密

利用java自带的MD5加密

作者头像
用户5640963
发布2019-07-26 10:26:52
1.1K0
发布2019-07-26 10:26:52
举报
文章被收录于专栏:卯金刀GG卯金刀GG

使用混淆的字符串是:{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}

package com.test;

import java.security.MessageDigest;

public class MD5Utils { private static final char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

/** * 加密 * @param pwd * @return */ public static String hash(String pwd){ if (pwd == null) { return null; } try { byte[] btInput = pwd.getBytes(); MessageDigest mdInst = MessageDigest.getInstance("MD5"); mdInst.update(btInput); byte[] md = mdInst.digest(); int j = md.length; char str[] = new char[j * 2]; int k = 0; for (int i = 0; i < j; i++) { byte byte0 = md[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); } catch (Exception e) { e.printStackTrace(); return null; }

} /** * 验证 * @param oldPwd * @param hash * @return */ public static boolean match(String str , String hash){ if (hash == null || str == null) { return false; } return hash.equals(hash(str)); } public static void main(String[] args){ // long timeStamp = System.currentTimeMillis(); long timeStamp = Long.parseLong("201704271034"); String sign = MD5Utils.hash("444"+timeStamp); System.out.println(sign); } }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档