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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to