longjy commented on issue #3959: Get ciphertext column as a string
URL: 
https://github.com/apache/incubator-shardingsphere/pull/3959#issuecomment-575967925
 
 
   table
   
   name | type
   ---|---
   id | bigint
   amount | varchar
   
   bean
   ```
   class Table{
       private Long id;
       private Bigdecimal amount;
   }
   ```
   ShardingEncryptor
   ```
      //plaintext is Bigdecimal type  
      @Override
       public String encrypt(Object plaintext) {
           return "test" + plaintext.toString();
       }
   
      //ciphertext is string
       @Override
       public Object decrypt(String ciphertext) {
           return new BigDecimal(ciphertext.replace("test", ""));
       }
   ```
   
   
   As shown above,amount is encrypted field,sql is
   ```
   select * from table;
   ```
   The original code  will be
   ```
   mergedResult.getValue(2, Bigdecimal.class);
   ```
   but db amount column is "testXXXX";  
   throw  exception:
   ```
   java.sql.SQLDataException: Cannot determine value type from string 
"testXXXXX"
   ```
   If mergedResult.getValue(2, String.class) get ciphertext,then 
ShardingEncryptor decrypt to Bigdecimal. will avoid this problem.
   
   If the table column is encrypted without affecting the type modification in 
the code, it will be easier for the user to access
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to