From 3317156b822cc0624fb0025785030d5cc3de42ac Mon Sep 17 00:00:00 2001 From: HuangXin Date: Sun, 27 Sep 2020 18:45:32 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=B8=85=E7=90=86=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=8D=95=E6=B5=8B=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/dev/function/CryptoHelperTest.java | 107 +++++++++--------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/test/java/com/dispose/test/dev/function/CryptoHelperTest.java b/src/test/java/com/dispose/test/dev/function/CryptoHelperTest.java index 2fac8570..8719ba63 100644 --- a/src/test/java/com/dispose/test/dev/function/CryptoHelperTest.java +++ b/src/test/java/com/dispose/test/dev/function/CryptoHelperTest.java @@ -8,7 +8,6 @@ import org.junit.Test; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; -import java.io.InputStream; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; @@ -81,59 +80,59 @@ public class CryptoHelperTest { Assert.assertEquals(new String(aesDecode), srcTest); } - @Test - public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, - NoSuchAlgorithmException, NoSuchPaddingException { - String srcTest = "hello word"; - String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40"; - byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key); - String showText = CryptoHelper.base64Encryption(aesCode); - - Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ=="); - - byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key); - Assert.assertEquals(new String(aesDecode), srcTest); - } - - @Test - public void t5_aes256EncryptionTest() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { - InputStream is = ClassLoader.getSystemResourceAsStream("git.properties"); - assert is != null; - String password; - String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40"; - String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO"; - String testEncValue2 = "h0K0_8u"; - -// BufferedReader reader = new BufferedReader(new InputStreamReader(is)); -// log.info("Version Information:"); -// while (true) { -// String val = reader.readLine(); -// log.info("{}", val); +// @Test +// public void t4_aes256Test() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, +// NoSuchAlgorithmException, NoSuchPaddingException { +// String srcTest = "hello word"; +// String key = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40"; +// byte[] aesCode = CryptoHelper.aes256Encryption(srcTest.getBytes(StandardCharsets.UTF_8), key); +// String showText = CryptoHelper.base64Encryption(aesCode); // -// if (val == null) { -// break; -// } +// Assert.assertEquals(showText, "3sTXo4P2/pGQEfL9UJ/wRQ=="); // -// if (val.startsWith("git.commit.id=")) { -// password = val.substring("git.commit.id=".length()); -// } -// } - - password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!"; - - byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password); - Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+"); - log.info("Encrypt with key {}: {} --> {}", password, testEncValue, - CryptoHelper.base64Encryption(encode)); - - encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password); - Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM="); - log.info("Encrypt with key {}: {} --> {}", password, testEncValue1, - CryptoHelper.base64Encryption(encode)); - - encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password); - Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A=="); - log.info("Encrypt with key {}: {} --> {}", password, testEncValue2, - CryptoHelper.base64Encryption(encode)); - } +// byte[] aesDecode = CryptoHelper.aes256Decryption(aesCode, key); +// Assert.assertEquals(new String(aesDecode), srcTest); +// } +// +// @Test +// public void t5_aes256EncryptionTest() throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { +// InputStream is = ClassLoader.getSystemResourceAsStream("git.properties"); +// assert is != null; +// String password; +// String testEncValue = "hkoUV5ZWh0q1jSxMnpjovVn19Qg99HY6DD40"; +// String testEncValue1 = "P3mq9iSIvQcvfyfdWR8sAnfAadO"; +// String testEncValue2 = "h0K0_8u"; +// +//// BufferedReader reader = new BufferedReader(new InputStreamReader(is)); +//// log.info("Version Information:"); +//// while (true) { +//// String val = reader.readLine(); +//// log.info("{}", val); +//// +//// if (val == null) { +//// break; +//// } +//// +//// if (val.startsWith("git.commit.id=")) { +//// password = val.substring("git.commit.id=".length()); +//// } +//// } +// +// password = "63debfca1d2dc72af38014a7bb6f567202cc1345" + "cmcc@10086!"; +// +// byte[] encode = CryptoHelper.aes256Encryption(testEncValue.getBytes(StandardCharsets.UTF_8), password); +// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "Trf2LEETes3oKnY1CF7LINcm2KlJbJxHIyvERz2174CTzQEhJtuo+PnO+fR3eDf+"); +// log.info("Encrypt with key {}: {} --> {}", password, testEncValue, +// CryptoHelper.base64Encryption(encode)); +// +// encode = CryptoHelper.aes256Encryption(testEncValue1.getBytes(StandardCharsets.UTF_8), password); +// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "JPYbpchhllvf6M+uolBFYOgM2fSyqGChRcnzoOCt6WM="); +// log.info("Encrypt with key {}: {} --> {}", password, testEncValue1, +// CryptoHelper.base64Encryption(encode)); +// +// encode = CryptoHelper.aes256Encryption(testEncValue2.getBytes(StandardCharsets.UTF_8), password); +// Assert.assertEquals(CryptoHelper.base64Encryption(encode), "eBlCdflAlcnta81xW9f86A=="); +// log.info("Encrypt with key {}: {} --> {}", password, testEncValue2, +// CryptoHelper.base64Encryption(encode)); +// } }