You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kylin.apache.org by GitBox <gi...@apache.org> on 2018/09/26 11:35:47 UTC

[GitHub] shaofengshi closed pull request #258: KYLIN-3356 Constant in SecretKeySpec

shaofengshi closed pull request #258: KYLIN-3356 Constant in SecretKeySpec
URL: https://github.com/apache/kylin/pull/258
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-common/src/main/java/org/apache/kylin/common/util/EncryptUtil.java b/core-common/src/main/java/org/apache/kylin/common/util/EncryptUtil.java
index deb54d4749..191b3cd06a 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/EncryptUtil.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/EncryptUtil.java
@@ -19,6 +19,8 @@
 package org.apache.kylin.common.util;
 
 import java.nio.charset.StandardCharsets;
+import java.security.SecureRandom;
+
 import org.apache.commons.codec.binary.Base64;
 
 import javax.crypto.Cipher;
@@ -28,8 +30,10 @@
     /**
      * thisIsAsecretKey
      */
-    private static byte[] key = { 0x74, 0x68, 0x69, 0x73, 0x49, 0x73, 0x41, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b,
-            0x65, 0x79 };
+    private static byte[] key = new byte[16];
+    {
+        new SecureRandom().nextBytes(key);
+    }
 
     public static String encrypt(String strToEncrypt) {
         try {
diff --git a/core-common/src/test/java/org/apache/kylin/common/util/EncryptUtilTest.java b/core-common/src/test/java/org/apache/kylin/common/util/EncryptUtilTest.java
index bc1c3e7ae4..717a94afed 100644
--- a/core-common/src/test/java/org/apache/kylin/common/util/EncryptUtilTest.java
+++ b/core-common/src/test/java/org/apache/kylin/common/util/EncryptUtilTest.java
@@ -27,7 +27,14 @@
     public void testAESEncrypt(){
         String input = "hello world";
         String result = EncryptUtil.encrypt(input);
-        Assert.assertEquals("4stv/RRleOtvie/8SLHmXA==", result);
+        Assert.assertEquals("dImt2pa7nDD7STLgdzFXGg==", result);
+    }
+
+    @Test
+    public void testAESDecrypt(){
+        String input = "F2nAgzbBcGRs8wtObIaXfQ==";
+        String result = EncryptUtil.decrypt(input);
+        Assert.assertEquals("wordcount", result);
     }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services