diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaEncryptor.java b/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaDecryptor.java similarity index 86% rename from orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaEncryptor.java rename to orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaDecryptor.java index a0edc757..a0bec1ae 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaEncryptor.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/interfaces/RsaDecryptor.java @@ -23,21 +23,13 @@ package org.dromara.visor.common.interfaces; /** - * rsa 加密器 + * rsa 解密器 * * @author Jiahang Li * @version 1.0.0 * @since 2025/1/5 20:58 */ -public interface RsaEncryptor { - - /** - * 加密 - * - * @param value value - * @return value - */ - String encrypt(String value); +public interface RsaDecryptor { /** * 解密 diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java b/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaParamDecryptUtils.java similarity index 70% rename from orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java rename to orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaParamDecryptUtils.java index b048b6b2..56b24887 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaEncryptUtils.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/utils/RsaParamDecryptUtils.java @@ -23,30 +23,20 @@ package org.dromara.visor.common.utils; import cn.orionsec.kit.lang.utils.Exceptions; -import org.dromara.visor.common.interfaces.RsaEncryptor; +import org.dromara.visor.common.interfaces.RsaDecryptor; /** - * rsa 加密工具类 + * rsa 参数解密工具类 * * @author Jiahang Li * @version 1.0.0 * @since 2025/1/5 21:13 */ -public class RsaEncryptUtils { +public class RsaParamDecryptUtils { - private static RsaEncryptor delegate; + private static RsaDecryptor delegate; - private RsaEncryptUtils() { - } - - /** - * 加密 - * - * @param value value - * @return value - */ - public static String encrypt(String value) { - return delegate.encrypt(value); + private RsaParamDecryptUtils() { } /** @@ -59,12 +49,12 @@ public class RsaEncryptUtils { return delegate.decrypt(value); } - public static void setDelegate(RsaEncryptor delegate) { - if (RsaEncryptUtils.delegate != null) { + public static void setDelegate(RsaDecryptor delegate) { + if (RsaParamDecryptUtils.delegate != null) { // unmodified throw Exceptions.state(); } - RsaEncryptUtils.delegate = delegate; + RsaParamDecryptUtils.delegate = delegate; } } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java index 2157a14b..f6e942be 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/configuration/OrionEncryptAutoConfiguration.java @@ -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; } } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaEncryptorImpl.java b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaDecryptorImpl.java similarity index 72% rename from orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaEncryptorImpl.java rename to orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaDecryptorImpl.java index be53e73a..1b482252 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaEncryptorImpl.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-encrypt/src/main/java/org/dromara/visor/framework/encrypt/core/impl/RsaDecryptorImpl.java @@ -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 publicKey; + private static final String SPLIT = "\\|"; private final ConfigRef 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()); } } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java index 608367a2..fee715dd 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/core/deserializer/ParamDecryptDeserializer.java @@ -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 { return value; } // 解密参数 - String decrypt = RsaEncryptUtils.decrypt(value); + String decrypt = RsaParamDecryptUtils.decrypt(value); return Valid.notNull(decrypt, ErrorMessage.DECRYPT_ERROR); } diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/config/strategy/HostSshConfigStrategy.java b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/config/strategy/HostSshConfigStrategy.java index 0fd5da54..d20f46d7 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/config/strategy/HostSshConfigStrategy.java +++ b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/config/strategy/HostSshConfigStrategy.java @@ -29,7 +29,7 @@ import org.dromara.visor.common.constant.Const; import org.dromara.visor.common.constant.ErrorMessage; import org.dromara.visor.common.handler.data.strategy.AbstractGenericsDataStrategy; 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.common.utils.Valid; import org.dromara.visor.module.asset.dao.HostIdentityDAO; import org.dromara.visor.module.asset.dao.HostKeyDAO; @@ -134,7 +134,7 @@ public class HostSshConfigStrategy extends AbstractGenericsDataStrategy => { // 为空直接返回 @@ -9,14 +12,32 @@ export const encrypt = async (data: string | undefined): Promise { + const encrypted = encryptor.encrypt(chunk); + if (encrypted === false) { + throw new Error(); + } + return encrypted; + }); + return encryptedChunks.join('|'); + } catch (error) { Message.error('数据加密失败'); throw new Error('数据加密失败'); } - return value; +}; + +// 分割字符串 +const splitString = (str: string): string[] => { + const chunks: string[] = []; + for (let i = 0; i < str.length; i += BLOCK_SIZE) { + chunks.push(str.slice(i, i + BLOCK_SIZE)); + } + return chunks; };