【fix sonar】SecurityTools文件
This commit is contained in:
+6
-7
@@ -8,12 +8,16 @@ import cn.hutool.crypto.asymmetric.RSA;
|
|||||||
import cn.hutool.crypto.asymmetric.Sign;
|
import cn.hutool.crypto.asymmetric.Sign;
|
||||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.jero.common.util.security.entity.*;
|
import com.jero.common.util.security.entity.*;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
|
|
||||||
public class SecurityTools {
|
public class SecurityTools {
|
||||||
|
|
||||||
|
private SecurityTools(){
|
||||||
|
|
||||||
|
}
|
||||||
public static final String ALGORITHM = "AES/ECB/PKCS5Padding";
|
public static final String ALGORITHM = "AES/ECB/PKCS5Padding";
|
||||||
|
|
||||||
public static SecurityResp valid(SecurityReq req) {
|
public static SecurityResp valid(SecurityReq req) {
|
||||||
@@ -28,12 +32,10 @@ public class SecurityTools {
|
|||||||
|
|
||||||
|
|
||||||
byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
|
byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
|
||||||
//log.info("rsa解密后的秘钥"+ Base64Encoder.encode(decryptAes));
|
|
||||||
AES aes = SecureUtil.aes(decryptAes);
|
AES aes = SecureUtil.aes(decryptAes);
|
||||||
|
|
||||||
String dencrptValue =aes.decryptStr(data);
|
String dencrptValue =aes.decryptStr(data);
|
||||||
//log.info("解密后报文"+dencrptValue);
|
resp.setData(JSON.parseObject(dencrptValue));
|
||||||
resp.setData(JSONObject.parseObject(dencrptValue));
|
|
||||||
|
|
||||||
boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
|
boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
|
||||||
resp.setSuccess(verify);
|
resp.setSuccess(verify);
|
||||||
@@ -51,13 +53,10 @@ public class SecurityTools {
|
|||||||
String encrptData =aes.encryptBase64(data);
|
String encrptData =aes.encryptBase64(data);
|
||||||
RSA rsa=new RSA(prikey,null);
|
RSA rsa=new RSA(prikey,null);
|
||||||
byte[] encryptAesKey = rsa.encrypt(secretKey.getEncoded(), KeyType.PrivateKey);
|
byte[] encryptAesKey = rsa.encrypt(secretKey.getEncoded(), KeyType.PrivateKey);
|
||||||
//log.info(("rsa加密过的秘钥=="+Base64Encoder.encode(encryptAesKey));
|
|
||||||
|
|
||||||
Sign sign= new Sign(SignAlgorithm.SHA1withRSA,prikey,null);
|
Sign sign= new Sign(SignAlgorithm.SHA1withRSA,prikey,null);
|
||||||
byte[] signed = sign.sign(data.getBytes());
|
byte[] signed = sign.sign(data.getBytes());
|
||||||
|
|
||||||
//log.info(("签名数据===》》"+Base64Encoder.encode(signed));
|
|
||||||
|
|
||||||
SecuritySignResp resp=new SecuritySignResp();
|
SecuritySignResp resp=new SecuritySignResp();
|
||||||
resp.setAesKey(Base64Encoder.encode(encryptAesKey));
|
resp.setAesKey(Base64Encoder.encode(encryptAesKey));
|
||||||
resp.setData(encrptData);
|
resp.setData(encrptData);
|
||||||
|
|||||||
Reference in New Issue
Block a user