You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "GaoEinstein (via GitHub)" <gi...@apache.org> on 2023/07/18 01:58:08 UTC

[GitHub] [shardingsphere] GaoEinstein commented on issue #25641: Add a new field (original type of entity-field) to the “EncryptContext” during EncryptAlgorithm#decrypt

GaoEinstein commented on issue #25641:
URL: https://github.com/apache/shardingsphere/issues/25641#issuecomment-1639162377

   A relatively simple solution may be as follows.
   
   `
   @RequiredArgsConstructor
   @Getter
   @Setter
   public final class TypedEncryptContext {
   
       private final EncryptContext encryptContext;
   
       /**
        * entity字段的原始类型
        */
       private final Class<?> entityFieldType;
   }
   `
   `
   public interface TypedEncryptAlgorithm<I, O> {
   
       /**
        * 数据库中某字段的数据解密
        * @param cipherValue 数据库中存储的密文
        * @param encryptContext 上下文
        * @return 解密结果
        */
       I decrypt(O cipherValue, TypedEncryptContext encryptContext);
   }
   `
   
   `
   public final class TypedEncryptAlgorithmAdapter {
   
       public static Object decrypt(Object cipherValue, EncryptContext encryptContext, StandardEncryptAlgorithm delegate,
                               Class<?> type) {
           if (delegate instanceof TypedEncryptAlgorithm) {
               TypedEncryptContext typedEncryptContext = new TypedEncryptContext(encryptContext, type);
               return ((TypedEncryptAlgorithm) delegate).decrypt(cipherValue, typedEncryptContext);
           }
           return delegate.decrypt(cipherValue, encryptContext);
       }
   
   }
   `
   An alternative solution would be to override the SPI, EncryptResultDecoratorEngine, by modifying META-INF/services/org.apache.shardingsphere.infra.merge.engine.ResultProcessEngine. Additionally, we can override EncryptDQLResultDecorator and EncryptMergedResult. By implementing TypedEncryptAlgorithmAdapter in org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult#getValue, we can execute the decryption process and effectively address this issue.
   
   If the official version allows modifications in org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult#getValue by adding the field type to the context, the work I have done above would be unnecessary.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org