GaoEinstein opened a new issue, #25641:
URL: https://github.com/apache/shardingsphere/issues/25641

   ### Is your feature request related to a problem?
   When I am using the sharding encryption jdbc module, I want to achieve 
automatic type conversion of ciphertext fields after decryption, such as the 
amount - BigDecimal. However, EncryptContext lacks an original field type 
configuration, so I would like to propose a requirement to add a field that can 
be used in my decryption method
   
   ### Describe the feature you would like.
   code position:
   org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult#getValue
   
   `    @Override
       public Object getValue(final int columnIndex, final Class<?> type) 
throws SQLException {
           Optional<EncryptContext> encryptContext = 
metaData.findEncryptContext(columnIndex);
           if (!encryptContext.isPresent() || 
!metaData.isQueryWithCipherColumn(encryptContext.get().getTableName(), 
encryptContext.get().getColumnName())) {
               return mergedResult.getValue(columnIndex, type);
           }
           Optional<EncryptAlgorithm> encryptAlgorithm = 
metaData.findEncryptor(encryptContext.get().getTableName(), 
encryptContext.get().getColumnName());
           if (!encryptAlgorithm.isPresent()) {
               return mergedResult.getValue(columnIndex, type);
           }
           Object cipherValue = mergedResult.getValue(columnIndex, 
Object.class);
   
          // add this line
           encryptContext.get().setEntityFiledType(type);
   
           return null == cipherValue ? null : 
encryptAlgorithm.get().decrypt(cipherValue, encryptContext.get());
       }`
   
   then usage in org.apache.shardingsphere.encrypt.algorithm.AESEncryptAlgorithm
   
   // org.apache.shardingsphere.encrypt.algorithm.AESEncryptAlgorithm#decrypt
   
   `public Object decrypt(String ciphertext, EncryptContext encryptContext) {
           if (null == ciphertext) {
               return null;
           }
   
           byte[] result = 
getCipher(Cipher.DECRYPT_MODE).doFinal(Base64.getDecoder().decode(ciphertext));
           String s =  new String(result, StandardCharsets.UTF_8);
   
           // add this line
           if (encryptContext.getEntityFiledType() == BigDecimal.class) {
               return new BigDecimal(s);
           }
   
           // todo date、localDate、localDateTime
   
           return s;
       }`
   
   Hope to help solve or answer the problem!thank you very much~


-- 
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