当前位置:网站首页>MD5 encryption verification
MD5 encryption verification
2022-07-28 16:54:00 【Ride a fish ~ cross the sea】
1. Import dependence
<!-- Join in MD5 Dependencies required for encryption -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
2. Create a tool class
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 encryption algorithm */
public class MD5Utils {
/** * MD5 Method * @param text Plaintext * @return Ciphertext * @throws Exception */
public static String md5(String text){
// The encrypted string
String encode= DigestUtils.md5Hex(text);
return encode;
}
/** * MD5 Method * @param text Plaintext * @param key salt * @return Ciphertext * @throws Exception */
public static String md5(String text, String key){
// The encrypted string
String encode= DigestUtils.md5Hex(text + key);
return encode;
}
/** * MD5 Verification method * @param text Plaintext * @param key secret key * @param md5 Ciphertext * @return true/false * @throws Exception */
public static boolean verify(String text, String key, String md5) throws Exception {
// Verify against the incoming key
String md5Text = md5(text, key);
return md5Text.equalsIgnoreCase(md5);
}
public static void main(String[] args) {
// Generate
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();
}
}
}
边栏推荐
- asp.net大文件分块上传断点续传demo
- Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)
- 微软:Edge 浏览器已内置磁盘缓存压缩技术,可节省空间占用且不降低系统性能
- How should I understand craft
- LwIP development | socket | UDP
- Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
- 给定正整数N、M,均介于1~10 ^ 9之间,N <= M,找出两者之间(含N、M)的位数为偶数的数有多少个
- Ansa secondary development - two methods of drawing the middle surface
- Epoll horizontal departure, which edge triggers
- 有趣的 Kotlin 0x09:Extensions are resolved statically
猜你喜欢

Interesting kotlin 0x0a:fun with composition

Interesting kotlin 0x06:list minus list

Sort 5-count sort

LeetCode每日一练 —— 160. 相交链表

Sort 1-insert sort and Hill sort

FX3开发板 及 原理图

快速掌握 Kotlin 集合函数

Interesting kotlin 0x07:composition

Im im development optimization improves connection success rate, speed, etc

Sort 3-select sort and merge sort (recursive implementation + non recursive implementation)
随机推荐
微软100题-天天做-第16题
Leetcode daily practice - 160. Cross linked list
Cluster construction and use of redis5
[JS] eight practical new functions of 1394-es2022
小程序:获取元素节点信息
【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
Leetcode647. Palindrome substring
【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)
Best Cow Fences 题解
Sort 2 bubble sort and quick sort (recursive and non recursive explanation)
我该如何理解工艺
Multiple commands produce ‘.../xxx.app/Assets.car‘问题
ticdc同步数据怎么设置只同步指定的库?
Efficiency comparison of three methods for obtaining timestamp
MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
Epoll horizontal departure, which edge triggers
Brother Ali teaches you how to correctly understand the problem of standard IO buffer
Multiple commands produce '... /xxx.app/assets.car' problem
Hdu1847 problem solving ideas
13 differences between MySQL and Oracle