You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/06/21 07:01:40 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #10830: Update AESEncryptAlgorithm.java

terrymanu commented on a change in pull request #10830:
URL: https://github.com/apache/shardingsphere/pull/10830#discussion_r655120406



##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithm.java
##########
@@ -35,56 +32,63 @@
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 import java.util.Properties;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
 
 /**
  * AES encrypt algorithm.
  */
 @Getter
 @Setter
 public final class AESEncryptAlgorithm implements EncryptAlgorithm {
-    
+
     private static final String AES_KEY = "aes-key-value";
-    
+
     private Properties props = new Properties();
-    
+
     private byte[] secretKey;
-    
+
     @Override
     public void init() {
         secretKey = createSecretKey();
     }
-    
+
     private byte[] createSecretKey() {
         Preconditions.checkArgument(props.containsKey(AES_KEY), String.format("%s can not be null.", AES_KEY));
         return Arrays.copyOf(DigestUtils.sha1(props.getProperty(AES_KEY)), 16);
     }
-    
+
     @SneakyThrows(GeneralSecurityException.class)
     @Override
     public String encrypt(final Object plaintext) {
         if (null == plaintext) {
             return null;
         }
-        byte[] result = getCipher(Cipher.ENCRYPT_MODE).doFinal(StringUtils.getBytesUtf8(String.valueOf(plaintext)));
-        return Base64.encodeBase64String(result);
+        byte[] result = new byte[0];
+        try {
+            result = getCipher(Cipher.ENCRYPT_MODE).doFinal(String.valueOf(plaintext).getBytes("UTF-8"));
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();

Review comment:
       Please do not use `printStackTrace`, it is better to process exception appropriately

##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithm.java
##########
@@ -35,56 +32,63 @@
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 import java.util.Properties;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
 
 /**
  * AES encrypt algorithm.
  */
 @Getter
 @Setter
 public final class AESEncryptAlgorithm implements EncryptAlgorithm {
-    
+

Review comment:
       Please do not change the original indent, please just change necessary codes.




-- 
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:
users@infra.apache.org