当前位置:网站首页>MD5加密验证
MD5加密验证
2022-07-28 15:45:00 【骑鱼~过海】
1.导入依赖
<!-- 加入MD5加密需要的依赖-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
2.创建工具类
String KEY_MD5=“easy0afshjd5fshkja48aodkjdf8sfsd”;
package tian.project.easy_to_stop.utils;
import org.apache.commons.codec.digest.DigestUtils;
import tian.project.easy_to_stop.constant.Constant;
/** * MD5加密算法 */
public class MD5Utils {
/** * MD5方法 * @param text 明文 * @return 密文 * @throws Exception */
public static String md5(String text){
//加密后的字符串
String encode= DigestUtils.md5Hex(text);
return encode;
}
/** * MD5方法 * @param text 明文 * @param key 盐 * @return 密文 * @throws Exception */
public static String md5(String text, String key){
//加密后的字符串
String encode= DigestUtils.md5Hex(text + key);
return encode;
}
/** * MD5验证方法 * @param text 明文 * @param key 密钥 * @param md5 密文 * @return true/false * @throws Exception */
public static boolean verify(String text, String key, String md5) throws Exception {
//根据传入的密钥进行验证
String md5Text = md5(text, key);
return md5Text.equalsIgnoreCase(md5);
}
public static void main(String[] args) {
//生成
try {
String var = md5("123456", Constant.KEY_MD5);
System.out.println(var);
boolean verify=verify("123456",Constant.KEY_MD5,"6eede222b0855e578b2c3813d2836f2d");
System.out.println(verify);
} catch (Exception e) {
e.printStackTrace();
}
}
}
边栏推荐
- 优化Hypermesh脚本性能的几点建议
- Each account corresponds to all passwords, and then each password corresponds to all accounts. How to write the brute force cracking code
- Thoughts on solving the pop-up of malicious computer advertisements
- ANSYS二次开发 - MFC界面调用ADPL文件
- Redis系列4:高可用之Sentinel(哨兵模式)
- IM即时通讯软件开发网络请求成功率的优化
- 2021-04-02
- The video Number finds the golden key, and Tiktok imitates the latecomers
- 栈的介绍与实现(详解)
- QT packaging
猜你喜欢

排序2-冒泡排序与快速排序(递归加非递归讲解)

IM即时通讯软件开发网络请求成功率的优化

ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境

Leetcode learn complex questions with random pointer linked lists (detailed explanation)

在vs code上配置Hypermesh二次开发环境

Configure HyperMesh secondary development environment on vs Code

LwIP development | realize TCP server through socket

ANSA二次开发 - 抽中面的两种方法

Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi

laravel
随机推荐
Reentrant and non reentrant
About mit6.828_ HW9_ Some problems of barriers xv6 homework9
“蔚来杯“2022牛客暑期多校训练营3 ACFHJ
每一个账号对应所有密码,再每一个密码对应所有账号暴力破解代码怎么写?...
The video Number finds the golden key, and Tiktok imitates the latecomers
Wechat official account to obtain material list
mysql cdc 如果binlog日志文件不全,全量阶段能读到所有数据吗
Geodetic coordinate system to Martian coordinate system
Redis series 4: sentinel (sentinel mode) with high availability
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
微软100题-天天做-第16题
快速掌握 Kotlin 集合函数
CRC16数据校验支持ModelBus和XMODEM校验模式(C语言)
Baidu editor ueeditor, when editing too much content, the toolbar is not visible, which is not convenient for editing or uploading problems
Qt学习之信号和槽机制
LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
LwIP development | socket | DNS domain name resolution
HDU1847解题思路
redis源码优化--绑核
ANSYS secondary development - MFC interface calls ADPL file