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

zhaojinchao 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 3b5d4a73621 Use MD5MessageDigestAlgorithm to replace MD5MaskAlgorithm 
and MD5AssistedEncryptAlgorithm (#30653)
3b5d4a73621 is described below

commit 3b5d4a73621ef80c27a56052fe875535f1934f5e
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Mar 26 14:58:32 2024 +0800

    Use MD5MessageDigestAlgorithm to replace MD5MaskAlgorithm and 
MD5AssistedEncryptAlgorithm (#30653)
---
 docs/document/content/dev-manual/infra-algorithm.cn.md   | 16 ++++++++++++++++
 docs/document/content/dev-manual/infra-algorithm.en.md   | 16 ++++++++++++++++
 features/encrypt/core/pom.xml                            |  5 +++++
 .../algorithm/assisted/MD5AssistedEncryptAlgorithm.java  | 15 +++++----------
 features/mask/core/pom.xml                               |  5 +++++
 .../mask/algorithm/hash/MD5MaskAlgorithm.java            | 11 +++++------
 6 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/docs/document/content/dev-manual/infra-algorithm.cn.md 
b/docs/document/content/dev-manual/infra-algorithm.cn.md
index fbfacbd908e..6d2364e3220 100644
--- a/docs/document/content/dev-manual/infra-algorithm.cn.md
+++ b/docs/document/content/dev-manual/infra-algorithm.cn.md
@@ -39,3 +39,19 @@ chapter = true
 
|-----------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | SNOWFLAKE       | 基于雪花算法的分布式主键生成算法    | 
[`org.apache.shardingsphere.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/snowflake/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/snowflake/SnowflakeKeyGenerateAlgorithm.java)
    |
 | UUID            | 基于 UUID 的分布式主键生成算法     | 
[`org.apache.shardingsphere.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/uuid/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/uuid/UUIDKeyGenerateAlgorithm.java)
                             |
+
+## MessageDigestAlgorithm
+
+### 全限定类名
+
+[`org.apache.shardingsphere.infra.algorithm.messagedigest.core.MessageDigestAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/message-digest/core/src/main/java/org/apache/shardingsphere/infra/algorithm/messagedigest/core/MessageDigestAlgorithm.java)
+
+### 定义
+
+消息摘要算法,可以使用在数据脱敏、数据加密功能中。
+
+### 已知实现
+
+| *配置标识* | *详细说明*      | *全限定类名*                                               
                                                                                
                                                                                
                                                                                
|
+|--------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| MD5    | MD5 消息摘要算法 | 
[`org.apache.shardingsphere.infra.algorithm.messagedigest.md5.MD5MessageDigestAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/message-digest/type/md5/src/main/java/org/apache/shardingsphere/infra/algorithm/messagedigest/md5/MD5MessageDigestAlgorithm.java)
    |
diff --git a/docs/document/content/dev-manual/infra-algorithm.en.md 
b/docs/document/content/dev-manual/infra-algorithm.en.md
index 58f26489a47..0b9d408e03a 100644
--- a/docs/document/content/dev-manual/infra-algorithm.en.md
+++ b/docs/document/content/dev-manual/infra-algorithm.en.md
@@ -39,3 +39,19 @@ Distributed key generated algorithms, they can be used in 
sharding feature.
 
|----------------------|----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | SNOWFLAKE            | Snowflake key generate algorithm | 
[`org.apache.shardingsphere.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/snowflake/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/snowflake/SnowflakeKeyGenerateAlgorithm.java)
 |
 | UUID                 | UUID key generate algorithm      | 
[`org.apache.shardingsphere.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/uuid/src/main/java/org/apache/shardingsphere/infra/algorithm/keygen/uuid/UUIDKeyGenerateAlgorithm.java)
                          |
+
+## MessageDigestAlgorithm
+
+### Fully-qualified class name
+
+[`org.apache.shardingsphere.infra.algorithm.messagedigest.core.MessageDigestAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/message-digest/core/src/main/java/org/apache/shardingsphere/infra/algorithm/messagedigest/core/MessageDigestAlgorithm.java)
+
+### Definition
+
+Message digest algorithms, they can be used in encrypt and mask feature.
+
+### Implementation classes
+
+| *Configuration Type* | *Description*                | *Fully-qualified class 
name*                                                                           
                                                                                
                                                                                
                               |
+|----------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| MD5    | MD5 message digest algorithm | 
[`org.apache.shardingsphere.infra.algorithm.messagedigest.md5.MD5MessageDigestAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/message-digest/type/md5/src/main/java/org/apache/shardingsphere/infra/algorithm/messagedigest/md5/MD5MessageDigestAlgorithm.java)
    |
diff --git a/features/encrypt/core/pom.xml b/features/encrypt/core/pom.xml
index cb1be72ded8..f9229753b57 100644
--- a/features/encrypt/core/pom.xml
+++ b/features/encrypt/core/pom.xml
@@ -47,6 +47,11 @@
             <artifactId>shardingsphere-mode-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-infra-algorithm-message-digest-md5</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
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 525aa87a35d..1a9d9c28279 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
@@ -19,10 +19,11 @@ package 
org.apache.shardingsphere.encrypt.algorithm.assisted;
 
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
 import 
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
+import 
org.apache.shardingsphere.infra.algorithm.messagedigest.core.MessageDigestAlgorithm;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 
 import java.util.Properties;
 
@@ -32,25 +33,19 @@ import java.util.Properties;
 @EqualsAndHashCode
 public final class MD5AssistedEncryptAlgorithm implements EncryptAlgorithm {
     
-    private static final String SALT_KEY = "salt";
-    
     @Getter
     private final EncryptAlgorithmMetaData metaData = new 
EncryptAlgorithmMetaData(false, true, false);
     
-    private String salt;
+    private MessageDigestAlgorithm digestAlgorithm;
     
     @Override
     public void init(final Properties props) {
-        salt = getSalt(props);
-    }
-    
-    private String getSalt(final Properties props) {
-        return props.getProperty(SALT_KEY, "");
+        digestAlgorithm = 
TypedSPILoader.getService(MessageDigestAlgorithm.class, getType(), props);
     }
     
     @Override
     public String encrypt(final Object plainValue, final AlgorithmSQLContext 
algorithmSQLContext) {
-        return null == plainValue ? null : DigestUtils.md5Hex(plainValue + 
salt);
+        return digestAlgorithm.digest(plainValue);
     }
     
     @Override
diff --git a/features/mask/core/pom.xml b/features/mask/core/pom.xml
index b954133f74f..e851a3eae3b 100644
--- a/features/mask/core/pom.xml
+++ b/features/mask/core/pom.xml
@@ -42,6 +42,11 @@
             <artifactId>shardingsphere-mode-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-infra-algorithm-message-digest-md5</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
diff --git 
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithm.java
 
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithm.java
index b02dd95a733..271bed2b123 100644
--- 
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithm.java
+++ 
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithm.java
@@ -17,7 +17,8 @@
 
 package org.apache.shardingsphere.mask.algorithm.hash;
 
-import org.apache.commons.codec.digest.DigestUtils;
+import 
org.apache.shardingsphere.infra.algorithm.messagedigest.core.MessageDigestAlgorithm;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
 
 import java.util.Properties;
@@ -27,18 +28,16 @@ import java.util.Properties;
  */
 public final class MD5MaskAlgorithm implements MaskAlgorithm<Object, String> {
     
-    private static final String SALT_KEY = "salt";
-    
-    private String salt;
+    private MessageDigestAlgorithm digestAlgorithm;
     
     @Override
     public void init(final Properties props) {
-        salt = props.getProperty(SALT_KEY, "");
+        digestAlgorithm = 
TypedSPILoader.getService(MessageDigestAlgorithm.class, getType(), props);
     }
     
     @Override
     public String mask(final Object plainValue) {
-        return null == plainValue ? null : DigestUtils.md5Hex(plainValue + 
salt);
+        return digestAlgorithm.digest(plainValue);
     }
     
     @Override

Reply via email to