🐛 修复加密失败的问题.

This commit is contained in:
lijiahangmax
2025-01-22 22:32:10 +08:00
parent aeb161a482
commit 4e5730f31f
7 changed files with 59 additions and 59 deletions

View File

@@ -25,12 +25,12 @@ package org.dromara.visor.framework.encrypt.configuration;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.AutoConfigureOrderConst;
import org.dromara.visor.common.interfaces.AesEncryptor;
import org.dromara.visor.common.interfaces.RsaEncryptor;
import org.dromara.visor.common.interfaces.RsaDecryptor;
import org.dromara.visor.common.utils.AesEncryptUtils;
import org.dromara.visor.common.utils.RsaEncryptUtils;
import org.dromara.visor.common.utils.RsaParamDecryptUtils;
import org.dromara.visor.framework.encrypt.configuration.config.AesEncryptConfig;
import org.dromara.visor.framework.encrypt.core.impl.AesEncryptorImpl;
import org.dromara.visor.framework.encrypt.core.impl.RsaEncryptorImpl;
import org.dromara.visor.framework.encrypt.core.impl.RsaDecryptorImpl;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -63,15 +63,15 @@ public class OrionEncryptAutoConfiguration {
/**
* @param configStore configStore
* @return rsa 密器
* @return rsa 参数解密器
*/
@Bean
public RsaEncryptor rsaEncryptor(ConfigStore configStore) {
// 密器
RsaEncryptor encryptor = new RsaEncryptorImpl(configStore);
public RsaDecryptor rsaParamDecryptor(ConfigStore configStore) {
// 密器
RsaDecryptor decryptor = new RsaDecryptorImpl(configStore);
// 设置工具类
RsaEncryptUtils.setDelegate(encryptor);
return encryptor;
RsaParamDecryptUtils.setDelegate(decryptor);
return decryptor;
}
}

View File

@@ -26,10 +26,11 @@ import cn.orionsec.kit.lang.utils.crypto.RSA;
import org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.ConfigKeys;
import org.dromara.visor.common.interfaces.RsaEncryptor;
import org.dromara.visor.common.interfaces.RsaDecryptor;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* rsa 加密器
@@ -38,25 +39,21 @@ import java.security.interfaces.RSAPublicKey;
* @version 1.0.0
* @since 2025/1/7 11:32
*/
public class RsaEncryptorImpl implements RsaEncryptor {
public class RsaDecryptorImpl implements RsaDecryptor {
private final ConfigRef<RSAPublicKey> publicKey;
private static final String SPLIT = "\\|";
private final ConfigRef<RSAPrivateKey> privateKey;
public RsaEncryptorImpl(ConfigStore configStore) {
this.publicKey = configStore.ref(ConfigKeys.ENCRYPT_PUBLIC_KEY, RSA::getPublicKey);
public RsaDecryptorImpl(ConfigStore configStore) {
this.privateKey = configStore.ref(ConfigKeys.ENCRYPT_PRIVATE_KEY, RSA::getPrivateKey);
}
@Override
public String encrypt(String value) {
return RSA.encrypt(value, publicKey.value);
}
@Override
public String decrypt(String value) {
return RSA.decrypt(value, privateKey.value);
return Arrays.stream(value.split(SPLIT))
.map(s -> RSA.decrypt(s, privateKey.value))
.collect(Collectors.joining());
}
}

View File

@@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import org.dromara.visor.common.constant.ErrorMessage;
import org.dromara.visor.common.utils.RsaEncryptUtils;
import org.dromara.visor.common.utils.RsaParamDecryptUtils;
import org.dromara.visor.common.utils.Valid;
import java.io.IOException;
@@ -51,7 +51,7 @@ public class ParamDecryptDeserializer extends JsonDeserializer<String> {
return value;
}
// 解密参数
String decrypt = RsaEncryptUtils.decrypt(value);
String decrypt = RsaParamDecryptUtils.decrypt(value);
return Valid.notNull(decrypt, ErrorMessage.DECRYPT_ERROR);
}