当前位置:网站首页>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();
}
}
}
边栏推荐
- 排序5-计数排序
- Abaqus GUI界面解决中文乱码问题(插件中文乱码也适用)
- PHP mb_ Substr Chinese garbled code
- LeetCode-学会对无序链表进行插入排序(详解)
- Leetcode daily practice - 160. Cross linked list
- “蔚来杯“2022牛客暑期多校训练营3 J.Journey 0-1最短路
- Sort 2 bubble sort and quick sort (recursive and non recursive explanation)
- The video Number finds the golden key, and Tiktok imitates the latecomers
- 排序3-选择排序与归并排序(递归实现+非递归实现)
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 3 j.journey 0-1 shortest path
猜你喜欢

小程序:获取元素节点信息

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

有趣的 Kotlin 0x08:What am I

HM二次开发 - Data Names及其使用

About the web docking pin printer, lodop uses

使用js直传oss阿里云存储文件,解决大文件上传服务器限制

ANSA二次开发 - 界面开发工具介绍

Thoughts on solving the pop-up of malicious computer advertisements

ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)

What does it remote operation and maintenance mean? Which is the best remote operation and maintenance software?
随机推荐
Reset grafana login password to default password
About the web docking pin printer, lodop uses
Detailed record of steps to configure web server (many references)
Using pyqt to design gui in ABAQUS
El input limit can only input the specified number
HyperMesh运行脚本文件的几种方法
有趣的 Kotlin 0x09:Extensions are resolved statically
Baidu editor ueeditor, when editing too much content, the toolbar is not visible, which is not convenient for editing or uploading problems
QT packaging
关于web对接针式打印机问题,Lodop使用
Rosen's QT journey 101 models and views in QT quick
Curl returns blank or null without output. Solve the problem
微软100题-天天做-第11题
PHP计算坐标距离
“蔚来杯“2022牛客暑期多校训练营3 ACFHJ
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Wechat official account to obtain material list
curl无输出返回空白或者null问题解决
Ansa secondary development - two methods of drawing the middle surface
Signal shielding and processing