This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push: new bd6c891 KYLIN-4438 fix bug: null password may cause RuntimeException when starting up bd6c891 is described below commit bd6c891dfc5f962630d2a2ae51d66880f1ef8037 Author: Congling Xia <xiacongl...@xiaomi.com> AuthorDate: Tue Mar 17 16:15:05 2020 +0800 KYLIN-4438 fix bug: null password may cause RuntimeException when starting up --- .../src/main/java/org/apache/kylin/common/util/EncryptUtil.java | 6 ++++++ .../src/test/java/org/apache/kylin/common/util/EncryptUtilTest.java | 6 ++++++ 2 files changed, 12 insertions(+) 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 deb54d4..c714eb2 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 @@ -32,6 +32,9 @@ public class EncryptUtil { 0x65, 0x79 }; public static String encrypt(String strToEncrypt) { + if (strToEncrypt == null) { + return null; + } try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); @@ -45,6 +48,9 @@ public class EncryptUtil { } public static String decrypt(String strToDecrypt) { + if (strToDecrypt == null) { + return null; + } try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); final SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); 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 bc1c3e7..f559229 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 @@ -30,5 +30,11 @@ public class EncryptUtilTest { Assert.assertEquals("4stv/RRleOtvie/8SLHmXA==", result); } + @Test + public void testNullInput() { + Assert.assertNull(EncryptUtil.encrypt(null)); + Assert.assertNull(EncryptUtil.decrypt(null)); + } + }