From e7329a4e4a137c6447eb384fb6704aa81add82d4 Mon Sep 17 00:00:00 2001 From: 632d6423b4d9145d677b07db <632d6423b4d9145d677b07db@devide> Date: Fri, 21 Apr 2023 11:58:43 +0000 Subject: [PATCH] Auto commit --- src/main/java/com/lhstack/utils/Aes.java | 14 ++++ src/main/resources/application.yml | 3 +- src/main/resources/static/index.html | 2 +- .../com/lhstack/TemplateApplicationTests.java | 46 +++++++++++++ target/classes/application.yml | 3 +- target/classes/com/lhstack/utils/Aes.class | Bin 1955 -> 2257 bytes target/classes/static/index.html | 2 +- .../default-testCompile/createdFiles.lst | 0 .../default-testCompile/inputFiles.lst | 1 + ...T-com.lhstack.TemplateApplicationTests.xml | 61 ++++++++++++++++++ .../com.lhstack.TemplateApplicationTests.txt | 4 ++ .../lhstack/TemplateApplicationTests.class | Bin 0 -> 2499 bytes 12 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/lhstack/TemplateApplicationTests.java create mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst create mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 target/surefire-reports/TEST-com.lhstack.TemplateApplicationTests.xml create mode 100644 target/surefire-reports/com.lhstack.TemplateApplicationTests.txt create mode 100644 target/test-classes/com/lhstack/TemplateApplicationTests.class diff --git a/src/main/java/com/lhstack/utils/Aes.java b/src/main/java/com/lhstack/utils/Aes.java index 931c35a..b0668f8 100644 --- a/src/main/java/com/lhstack/utils/Aes.java +++ b/src/main/java/com/lhstack/utils/Aes.java @@ -37,4 +37,18 @@ public class Aes { throw new RuntimeException(e); } } + + public static byte[] encrypt(String key,String iv,byte[] bytes){ + try{ + Cipher cipher = StringUtils.hasText(iv) ? Cipher.getInstance(CBC) : Cipher.getInstance(ECB); + if(StringUtils.hasText(iv)){ + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes(), "AES"), new IvParameterSpec(iv.getBytes())); + }else { + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes(), "AES")); + } + return cipher.doFinal(bytes); + }catch(Exception e){ + throw new RuntimeException(e); + } + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9e5e1a6..0b21986 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,2 +1,3 @@ aes: - key: axiwlazlf1456175 \ No newline at end of file + key: axiwlazlf1456175 + iv: 114aqws431@#!%_+ \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 3502d80..8740837 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -114,7 +114,7 @@ closed: false, aesKey: "", aesIv: "", - encryptText: "", + encryptText: "9GVtgT5fzydU1O595W+0fIPRew4IFoRUUijxalwx/pHe8ONGN2qvIIwah9bC0oj7QrcdrGfxO9klqwlc7ntUOantY5vb65DJDolUmX/RyU4A5T9DRD5I3tqn2pmaK3EjsSsba+FScfeLq5HTGM258OW2X0ryyPp7iw2s/anGlzw=", theme: "default", output: "", isJson: false, diff --git a/src/test/java/com/lhstack/TemplateApplicationTests.java b/src/test/java/com/lhstack/TemplateApplicationTests.java new file mode 100644 index 0000000..afaf56e --- /dev/null +++ b/src/test/java/com/lhstack/TemplateApplicationTests.java @@ -0,0 +1,46 @@ +package com.lhstack; + + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bouncycastle.util.encoders.Base64; +import org.bouncycastle.util.encoders.Hex; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.lhstack.utils.Aes; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class TemplateApplicationTests { + @Value("${aes.key:}") + private String defaultAesKey; + + @Value("${aes.iv:}") + private String defaultAesIv; + + @Test + public void test() throws Exception{ + Map data = new HashMap<>(); + data.put("date", new Date()); + data.put("time", System.currentTimeMillis()); + data.put("msg", "hello world"); + List list = Arrays.asList(1,2,3,4,5,6,7); + data.put("msg", list); + data.put("class", TemplateApplicationTests.class); + ObjectMapper objectMapper = new ObjectMapper(); + byte[] jsonBytes = objectMapper.writeValueAsBytes(data); + byte[] bytes = Aes.encrypt(defaultAesKey, defaultAesIv, jsonBytes); + System.out.println(new String(Base64.encode(bytes),StandardCharsets.UTF_8)); + System.out.println(new String(Hex.encode(bytes),StandardCharsets.UTF_8)); + } +} diff --git a/target/classes/application.yml b/target/classes/application.yml index 9e5e1a6..0b21986 100644 --- a/target/classes/application.yml +++ b/target/classes/application.yml @@ -1,2 +1,3 @@ aes: - key: axiwlazlf1456175 \ No newline at end of file + key: axiwlazlf1456175 + iv: 114aqws431@#!%_+ \ No newline at end of file diff --git a/target/classes/com/lhstack/utils/Aes.class b/target/classes/com/lhstack/utils/Aes.class index ba0dd662b1530603f7bf4f93d68e62bc9e9853f7..16efe5d05439e138430fcc16d5032963f9d6f4ea 100644 GIT binary patch delta 120 zcmZ3?e^HR@)W2Q(7#J8#7;-jp)wA-mr{*OWRTh*mGO#99mZVN@V|8I<*?gMyJR>tF zL&oGrHho5x$s5_^f#gLtb6IT$Q3f3b83tVjO9nj#8wPy_KL$gF5C$WLPzK}4s_cr4 VnUmew{dqHiRxmPT0ZAr?Yyico8y5fo delta 40 vcmca8xR{^o)W2Q(7#J8#7_v5U)w52X&FaX=y!kHcc}7k~h76zt6GJ8d9Bm7B diff --git a/target/classes/static/index.html b/target/classes/static/index.html index 3502d80..8740837 100644 --- a/target/classes/static/index.html +++ b/target/classes/static/index.html @@ -114,7 +114,7 @@ closed: false, aesKey: "", aesIv: "", - encryptText: "", + encryptText: "9GVtgT5fzydU1O595W+0fIPRew4IFoRUUijxalwx/pHe8ONGN2qvIIwah9bC0oj7QrcdrGfxO9klqwlc7ntUOantY5vb65DJDolUmX/RyU4A5T9DRD5I3tqn2pmaK3EjsSsba+FScfeLq5HTGM258OW2X0ryyPp7iw2s/anGlzw=", theme: "default", output: "", isJson: false, diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e8b6d1d --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/root/Java/src/test/java/com/lhstack/TemplateApplicationTests.java diff --git a/target/surefire-reports/TEST-com.lhstack.TemplateApplicationTests.xml b/target/surefire-reports/TEST-com.lhstack.TemplateApplicationTests.xml new file mode 100644 index 0000000..518a837 --- /dev/null +++ b/target/surefire-reports/TEST-com.lhstack.TemplateApplicationTests.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.lhstack.TemplateApplicationTests.txt b/target/surefire-reports/com.lhstack.TemplateApplicationTests.txt new file mode 100644 index 0000000..8e813c9 --- /dev/null +++ b/target/surefire-reports/com.lhstack.TemplateApplicationTests.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.lhstack.TemplateApplicationTests +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.48 s - in com.lhstack.TemplateApplicationTests diff --git a/target/test-classes/com/lhstack/TemplateApplicationTests.class b/target/test-classes/com/lhstack/TemplateApplicationTests.class new file mode 100644 index 0000000000000000000000000000000000000000..b0ce793c8e1dde983c594f8b7b8a60edbd7bff4d GIT binary patch literal 2499 zcma)7ZC4XV6n+*GHiT6mRx4WT8`uEi_65-r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