Java代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.ledao;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
* @author LeDao
* @company
* @create 2021-09-14 11:10
*/
public class Test {

public static void main(String[] args) {
//原始密码
String password = "123456";
//随机盐值
String salt = new SecureRandomNumberGenerator().nextBytes().toString();
//加密次数
int times = 2;
//加密算法
String encryptName = "md5";
//加密后的密码
String encodePassword = new SimpleHash(encryptName, password, salt, times).toString();
System.out.println(encodePassword);
}
}

测试

每次的加密结果都不同,因为每次的盐值都不同