update:加密解密逻辑修复

This commit is contained in:
luoluogit 2024-12-19 17:36:57 +08:00
parent 175d1e365a
commit 66463d8219
4 changed files with 7 additions and 7 deletions

View File

@ -111,7 +111,7 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
} }
}else if (StringUtils.isNotEmpty(userName)){ }else if (StringUtils.isNotEmpty(userName)){
try{ try{
String user = RSAUtil.decrypt(userName,RSAUtil.getPrivateKeyFromString()); String user = RSAUtil.decrypt(userName,RSAUtil.getPrivateKeyFromString(RSAUtil.privateKeyString));
result.setUser(user); result.setUser(user);
result.setSucess(true); result.setSucess(true);
logger.info("SSO用户登录成功进入苍穹系统"); logger.info("SSO用户登录成功进入苍穹系统");

View File

@ -176,7 +176,7 @@ public class ToDoResendTack extends AbstractTask {
"phone,username", new QFilter[]{new QFilter("id", "=", next.getString("freceiveuserid"))}); "phone,username", new QFilter[]{new QFilter("id", "=", next.getString("freceiveuserid"))});
String userName; String userName;
try { try {
userName = RSAUtil.decrypt(dynamicObject.getString("username"),RSAUtil.getPrivateKeyFromString()); userName = RSAUtil.decrypt(dynamicObject.getString("username"),RSAUtil.getPrivateKeyFromString(RSAUtil.publicKeyString));
}catch (Exception e){ }catch (Exception e){
ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!"); ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!");
throw new KDException(errorCode, e); throw new KDException(errorCode, e);

View File

@ -46,7 +46,7 @@ public class BacklogServiceHandle extends AbstractServiceHandler {
for (DynamicObject query_one : query) { for (DynamicObject query_one : query) {
String userName; String userName;
try { try {
userName = RSAUtil.encrypt(query_one.getString("username"),RSAUtil.getPublicKeyFromString()); userName = RSAUtil.encrypt(query_one.getString("username"),RSAUtil.getPublicKeyFromString(RSAUtil.publicKeyString));
}catch (Exception e){ }catch (Exception e){
logger.info("####公钥加密出现异常,请联系运维人员排查!"); logger.info("####公钥加密出现异常,请联系运维人员排查!");
ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!"); ErrorCode errorCode = new ErrorCode("error_code", "公钥加密出现异常,请联系运维人员排查!");

View File

@ -10,8 +10,8 @@ import java.util.Base64;
public class RSAUtil { public class RSAUtil {
private static String publicKeyString = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1XBGWkKD5/qmnaPJ8OWbypW8RIf8UPQIgTEVBaWNF4m5KwmtU9gO201s7aAJE2gW8tcpzjl+KtQUkxog1TnF5AmYDLXqgJb4N8vWGU5Vf+jJGzyzT2U7loDTGtgumzJJB3ySapAyPCGW3tyFMTZOEc+iVrCw2iOjzYUim0SKtzB4/3prJpEDfnjwM9BJYeG/2w9i+t5ZiSRLaCvSK2tm/4JflcKjommW/ImeD67wikCbnAD5HUAG9hLXL9ApW/1Z83YM83EfoFOQJNoSZ7NvSBTEuIzhoQCZHS0F/n1tSktAJvYLL2M5yG7/EdAb/zw8/ox63d+mvbDK/4sczst0AQIDAQAB"; public static String publicKeyString = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1XBGWkKD5/qmnaPJ8OWbypW8RIf8UPQIgTEVBaWNF4m5KwmtU9gO201s7aAJE2gW8tcpzjl+KtQUkxog1TnF5AmYDLXqgJb4N8vWGU5Vf+jJGzyzT2U7loDTGtgumzJJB3ySapAyPCGW3tyFMTZOEc+iVrCw2iOjzYUim0SKtzB4/3prJpEDfnjwM9BJYeG/2w9i+t5ZiSRLaCvSK2tm/4JflcKjommW/ImeD67wikCbnAD5HUAG9hLXL9ApW/1Z83YM83EfoFOQJNoSZ7NvSBTEuIzhoQCZHS0F/n1tSktAJvYLL2M5yG7/EdAb/zw8/ox63d+mvbDK/4sczst0AQIDAQAB";
private static String privateKeyString = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDVcEZaQoPn+qado8nw5ZvKlbxEh/xQ9AiBMRUFpY0XibkrCa1T2A7bTWztoAkTa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1JDCbg5zCU0Scz6LFnSc4UISajPEy0u7v8l74k2Tqr+XXOCAbG4gSr12BazQ7c7pT0hnwE1t/WKdeu033dbTfz+FkZ/ARFgfsjuGBrc2LA7A/FbOD28mTcQKBgQDrC41Z14Iz4N+hr4fvilCqou/GcF7T5CP//tKqj3RRgCYu3XF1btQ+iXMRc40NzdCdxmH+BMJ9lS51Soi0dzvHuQTn/A/3cviBfmzptqTMp0T2RpXQ0bSe4wqUT3fdenFm39xbw9p+b+eknZ8lrGM6fn06GBP6mQ+USMvZAnkdawKBgQDod5hasx8rMveJsNdqp/vGOFVtCh6RVX0rV8vlJ1tLGAhxBQbPbbmB/H773Fqyhc7NOWPFbSuHXtZtArgTY5wHwHcBZ41nB7E5Y40wMql8eNFhBFAb1M8xy7o+cX5gIsphrBRiGGM9MBhQNea2cH3flKW9NPKdvH3dF0sv/OGDQwKBgQClV60JpDZtdCUcwjPn5+6y+oedmnK6r+Q7MvDTFrMGmhVCJnin2Vzo2RvfDOAO89drBaDtZj/Cw+y4icP831toNdkjsAczVOdHgL3w8pCffpNeg2zkRoC+vIw2pGh3nqija5rB2taa1vGmtVK817W98jj5YvK6+G0jLMppT/oPHQKBgQC7S3Ai02Jvabbq5uIIeqNtxwF8wsRyD9CzVR9f11/Elu5mMMiV4y+tPQQKZDVm1EwUKQLrk9OYU56rYZ9xb7XMwRKgvQ++TQJK3JxqksbfFHCNm+33HnR5CE1b9hD938ny+7PIfSGnsNJF/ceOgf/IXXlTgg9favh1Y0ketr3zBQKBgFKWHvw/i1j4F/6vQIBn4ke22Ja8qXDNLfIUEcgqqvIx5N6Imv8DLyvu56CWveThVzk810VHRqoJ3aIgA8oTs/mQyd8G/S8jbyufl2GeoHap9azSr63HZh4v8ZBMQuA6xP2CEUByEyIWknwo7pp9yj8gJZUFmvTthY6SvkYrqg1H";
/** /**
* 加密 * 加密
@ -50,7 +50,7 @@ public class RSAUtil {
* @return 公钥 * @return 公钥
* @throws Exception 异常 * @throws Exception 异常
*/ */
public static PublicKey getPublicKeyFromString() throws Exception { public static PublicKey getPublicKeyFromString(String publicKeyString) throws Exception {
byte[] keyBytes = Base64.getDecoder().decode(publicKeyString); byte[] keyBytes = Base64.getDecoder().decode(publicKeyString);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); KeyFactory keyFactory = KeyFactory.getInstance("RSA");
@ -63,7 +63,7 @@ public class RSAUtil {
* @return 私钥 * @return 私钥
* @throws Exception 异常 * @throws Exception 异常
*/ */
public static PrivateKey getPrivateKeyFromString() throws Exception { public static PrivateKey getPrivateKeyFromString(String privateKeyString) throws Exception {
byte[] keyBytes = Base64.getDecoder().decode(privateKeyString); byte[] keyBytes = Base64.getDecoder().decode(privateKeyString);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); KeyFactory keyFactory = KeyFactory.getInstance("RSA");