From f1484e9f22aec24993f9798520ad7975b19cbd6d Mon Sep 17 00:00:00 2001 From: hujun3 <510830970@qq.com> Date: Fri, 25 Mar 2022 10:25:24 +0800 Subject: [PATCH] =?UTF-8?q?spi=20=E6=B7=BB=E5=8A=A0=E7=A7=98=E9=92=A5?= =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../encryption/handler/EncryptionHandler.java | 7 ++++--- .../encryption/spi/EncryptionPluginService.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/handler/EncryptionHandler.java b/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/handler/EncryptionHandler.java index b46a1172f..0bd17829c 100644 --- a/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/handler/EncryptionHandler.java +++ b/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/handler/EncryptionHandler.java @@ -61,7 +61,7 @@ public class EncryptionHandler { EncryptionPluginService encryptionPluginService = optional.get(); String secretKey = encryptionPluginService.generateSecretKey(); String encrypt = encryptionPluginService.encrypt(secretKey, content); - return Pair.with(secretKey, encrypt); + return Pair.with(secretKey, encryptionPluginService.encryptSecretKey(encrypt)); } /** @@ -84,8 +84,9 @@ public class EncryptionHandler { return Pair.with("", content); } EncryptionPluginService encryptionPluginService = optional.get(); - String decrypt = encryptionPluginService.decrypt(secretKey, content); - return Pair.with(secretKey, decrypt); + String decryptSecretKey = encryptionPluginService.decryptSecretKey(secretKey); + String decryptContent = encryptionPluginService.decrypt(decryptSecretKey, content); + return Pair.with(decryptSecretKey, decryptContent); } /** diff --git a/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/spi/EncryptionPluginService.java b/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/spi/EncryptionPluginService.java index 4dc85f2d5..d4707bc7c 100644 --- a/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/spi/EncryptionPluginService.java +++ b/plugin/encryption/src/main/java/com/alibaba/nacos/plugin/encryption/spi/EncryptionPluginService.java @@ -54,4 +54,18 @@ public interface EncryptionPluginService { * @return name */ String algorithmName(); + + /** + * encrypt secretKey. + * @param secretKey secretKey + * @return encrypted secretKey + */ + String encryptSecretKey(String secretKey); + + /** + * decrypt secretKey. + * @param secretKey secretKey + * @return decrypted secretKey + */ + String decryptSecretKey(String secretKey); }