【fix sonar】PasswordUtil文件
This commit is contained in:
+45
-6
@@ -1,13 +1,18 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Key;
|
||||
import java.security.SecureRandom;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.PBEParameterSpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Key;
|
||||
import java.security.SecureRandom;
|
||||
@Component
|
||||
public class PasswordUtil {
|
||||
|
||||
private PasswordUtil(){
|
||||
@@ -22,8 +27,32 @@ public class PasswordUtil {
|
||||
/**
|
||||
* 定义使用的算法为:PBEWITHMD5andDES算法
|
||||
*/
|
||||
public static final String ALGORITHM = "PBEWithMD5AndDES";//加密算法
|
||||
public static final String SALT = "63293188";//密钥
|
||||
//加密算法
|
||||
public static String ALGORITHM;
|
||||
@Value("${jero.password.pbe.algorithm}")
|
||||
private String algorithmStr;
|
||||
@PostConstruct
|
||||
public void setAlgorithm(){
|
||||
synchronized (PasswordUtil.class){
|
||||
if(ALGORITHM == null){
|
||||
ALGORITHM = this.algorithmStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String SALT;
|
||||
//密钥
|
||||
@Value("${jero.password.pbe.salt}")
|
||||
private String saltStr;
|
||||
@PostConstruct
|
||||
public void setSalt(){
|
||||
synchronized (PasswordUtil.class){
|
||||
if(SALT == null){
|
||||
SALT = this.saltStr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义迭代次数为1000次
|
||||
@@ -143,6 +172,17 @@ public class PasswordUtil {
|
||||
}
|
||||
return new String(passDec);
|
||||
}
|
||||
/**
|
||||
* 自定义加密明文字符串
|
||||
*
|
||||
* @param ciphertext
|
||||
* 待解密的密文字符串
|
||||
* @return 解密后的明文字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String ciphertext) {
|
||||
return decrypt(ciphertext, ALGORITHM, SALT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串
|
||||
@@ -193,5 +233,4 @@ public class PasswordUtil {
|
||||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -194,12 +194,12 @@ mybatis-plus:
|
||||
# 返回类型为Map,显示null对应的字段
|
||||
call-setters-on-nulls: true
|
||||
#jero专用配置
|
||||
jero :
|
||||
jero:
|
||||
# 签名密钥串(前后端要一致,正式发布请自行修改)
|
||||
signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a
|
||||
# 本地:local\Minio:minio\阿里云:alioss
|
||||
uploadType: local
|
||||
path :
|
||||
path:
|
||||
#文件上传根目录 设置
|
||||
upload: D://opt//upFiles
|
||||
#webapp文件路径
|
||||
@@ -273,6 +273,14 @@ jero :
|
||||
fileSuffixLimits : 0x00,%00,\\00,.jsp,.exe,.php,.asp,.aspx,.jspx,.xml,.html,.js,.sh,.bin
|
||||
# 跨站白名单
|
||||
whiteUrls:
|
||||
# 加密默认值
|
||||
password:
|
||||
pbe:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
salt: 63293188
|
||||
aes:
|
||||
encrypted_key: 1234567890adbcde
|
||||
encrypted_iv: 1234567890hjlkew
|
||||
#cas单点登录
|
||||
cas:
|
||||
prefixUrl: http://cas.example.org:8443/cas
|
||||
|
||||
@@ -195,12 +195,12 @@ mybatis-plus:
|
||||
# 返回类型为Map,显示null对应的字段
|
||||
call-setters-on-nulls: true
|
||||
#jero专用配置
|
||||
jero :
|
||||
jero:
|
||||
# 签名密钥串(前后端要一致,正式发布请自行修改)
|
||||
signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a
|
||||
# 本地:local\Minio:minio\阿里云:alioss
|
||||
uploadType: local
|
||||
path :
|
||||
path:
|
||||
#文件上传根目录 设置
|
||||
upload: D://opt//upFiles
|
||||
#webapp文件路径
|
||||
@@ -274,6 +274,14 @@ jero :
|
||||
fileSuffixLimits : 0x00,%00,\\00,.jsp,.exe,.php,.asp,.aspx,.jspx,.xml,.html,.js,.sh,.bin
|
||||
# 跨站白名单
|
||||
whiteUrls:
|
||||
# 加密默认值
|
||||
password:
|
||||
pbe:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
salt: 63293188
|
||||
aes:
|
||||
encrypted_key: 1234567890adbcde
|
||||
encrypted_iv: 1234567890hjlkew
|
||||
#cas单点登录
|
||||
cas:
|
||||
prefixUrl: http://cas.example.org:8443/cas
|
||||
|
||||
@@ -194,12 +194,12 @@ mybatis-plus:
|
||||
# 返回类型为Map,显示null对应的字段
|
||||
call-setters-on-nulls: true
|
||||
#jero专用配置
|
||||
jero :
|
||||
jero:
|
||||
# 签名密钥串(前后端要一致,正式发布请自行修改)
|
||||
signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a
|
||||
# 本地:local\Minio:minio\阿里云:alioss
|
||||
uploadType: local
|
||||
path :
|
||||
path:
|
||||
#文件上传根目录 设置
|
||||
upload: D://opt//upFiles
|
||||
#webapp文件路径
|
||||
@@ -273,6 +273,14 @@ jero :
|
||||
fileSuffixLimits : 0x00,%00,\\00,.jsp,.exe,.php,.asp,.aspx,.jspx,.xml,.html,.js,.sh,.bin
|
||||
# 跨站白名单
|
||||
whiteUrls:
|
||||
# 加密默认值
|
||||
password:
|
||||
pbe:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
salt: 63293188
|
||||
aes:
|
||||
encrypted_key: 1234567890adbcde
|
||||
encrypted_iv: 1234567890hjlkew
|
||||
#cas单点登录
|
||||
cas:
|
||||
prefixUrl: http://cas.example.org:8443/cas
|
||||
|
||||
Reference in New Issue
Block a user