This is an automated email from the ASF dual-hosted git repository.

chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f575762389 Optimize EncryptAlgorithm#toConfiguration. (#34734)
9f575762389 is described below

commit 9f575762389bdcec9874fe581e681c72211a84e0
Author: Cong Hu <iamhuc...@gmail.com>
AuthorDate: Fri Feb 21 16:41:58 2025 +0800

    Optimize EncryptAlgorithm#toConfiguration. (#34734)
---
 .../algorithm/assisted/MD5AssistedEncryptAlgorithm.java        |  6 +++++-
 .../encrypt/algorithm/standard/AESEncryptAlgorithm.java        | 10 +++++++++-
 .../algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java    |  4 ++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
index 27ea588c461..a0bf1f93358 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
@@ -32,6 +32,8 @@ import java.util.Properties;
  */
 public final class MD5AssistedEncryptAlgorithm implements EncryptAlgorithm {
     
+    private static final String SALT_KEY = "salt";
+    
     @Getter
     private final EncryptAlgorithmMetaData metaData = new 
EncryptAlgorithmMetaData(false, true, false);
     
@@ -57,7 +59,9 @@ public final class MD5AssistedEncryptAlgorithm implements 
EncryptAlgorithm {
     
     @Override
     public AlgorithmConfiguration toConfiguration() {
-        return new AlgorithmConfiguration(getType(), props);
+        Properties properties = new Properties();
+        properties.setProperty(SALT_KEY, props.getProperty(SALT_KEY, ""));
+        return new AlgorithmConfiguration(getType(), properties);
     }
     
     @Override
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
index 972debf14ae..8801ff1ac2e 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.encrypt.algorithm.standard;
 
 import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
@@ -32,6 +33,10 @@ import java.util.Properties;
  */
 public final class AESEncryptAlgorithm implements EncryptAlgorithm {
     
+    private static final String AES_KEY = "aes-key-value";
+    
+    private static final String DIGEST_ALGORITHM_NAME = 
"digest-algorithm-name";
+    
     @Getter
     private final EncryptAlgorithmMetaData metaData = new 
EncryptAlgorithmMetaData(true, true, false);
     
@@ -58,7 +63,10 @@ public final class AESEncryptAlgorithm implements 
EncryptAlgorithm {
     
     @Override
     public AlgorithmConfiguration toConfiguration() {
-        return new AlgorithmConfiguration(getType(), props);
+        Properties properties = new Properties();
+        properties.put(AES_KEY, props.getProperty(AES_KEY));
+        properties.put(DIGEST_ALGORITHM_NAME, 
StringUtils.upperCase(props.getProperty(DIGEST_ALGORITHM_NAME)));
+        return new AlgorithmConfiguration(getType(), properties);
     }
     
     @Override
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
index d952f1cd3e8..a332a1fade0 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 
 class MD5AssistedEncryptAlgorithmTest {
@@ -53,6 +52,7 @@ class MD5AssistedEncryptAlgorithmTest {
     void assertToConfiguration() {
         AlgorithmConfiguration actual = encryptAlgorithm.toConfiguration();
         assertThat(actual.getType(), is("MD5"));
-        assertTrue(actual.getProps().isEmpty());
+        assertThat(actual.getProps().size(), is(1));
+        assertThat(actual.getProps().getProperty("salt"), is(""));
     }
 }

Reply via email to