package com.doumee.core.utils;
|
|
import org.springframework.util.DigestUtils;
|
|
import java.util.Random;
|
|
/**
|
* 安全处理工具类
|
* @author Eva.Caesar Liu
|
* @date 2023/02/14 11:14
|
*/
|
public class Secure {
|
|
/**
|
* 加密密码
|
* @param password 密码
|
* @param salt 密码盐
|
*
|
* @return String
|
*/
|
public String encryptPassword(String password, String salt) {
|
return DigestUtils.md5DigestAsHex((password + salt).getBytes());
|
}
|
|
/**
|
* 随机生成8位密码盐
|
*
|
* @return
|
*/
|
public String getRandomSalt() {
|
char[] chars = ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
|
"1234567890").toCharArray();
|
StringBuilder sb = new StringBuilder();
|
for (int i = 0; i < 4; i++) {
|
//Random().nextInt()返回值为[0,n)
|
char aChar = chars[new Random().nextInt(chars.length)];
|
sb.append(aChar);
|
}
|
return sb.toString();
|
}
|
}
|