From 2d7e7fe8cf562f420bd9ffa46839768cb219512e Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Thu, 14 Mar 2024 23:25:28 +0800 Subject: [PATCH 1/8] update cloud.gradle --- build.gradle | 27 +++---------------- .../heliannuuthus/blog/BlogApplication.java | 3 ++- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index a753770..52876fb 100644 --- a/build.gradle +++ b/build.gradle @@ -3,24 +3,12 @@ plugins { id "org.springframework.boot" version "3.2.3" id "io.spring.dependency-management" version "1.1.4" id "org.springdoc.openapi-gradle-plugin" version "1.8.0" + id 'me.qoomon.git-versioning' version '6.4.2' + id "com.diffplug.spotless" version "6.25.0" + id "io.freefair.lombok" version "8.6" } -group = "io.ghcr.heliannuuthus" -java { - sourceCompatibility = "17" -} - -ext { - springOpenApiVersion = "2.3.0" - guavaVersion = "33.0.0-jre" - apacheCommonVersion = "3.14.0" -} - -configurations { - compileOnly { - extendsFrom annotationProcessor - } -} +apply from: "https://raw.gitmirror.com/heliannuuthus/integrate-deploy/master/gradle/cloud.gradle" repositories { maven { url "https://maven.aliyun.com/repository/public" } @@ -32,10 +20,6 @@ dependencies { implementation "org.springframework.boot:spring-boot-starter-data-r2dbc" implementation "org.springframework.boot:spring-boot-starter-webflux" - implementation "org.springdoc:springdoc-openapi-starter-webflux-ui:${springOpenApiVersion}" - implementation "com.google.guava:guava:${guavaVersion}" - implementation "org.apache.commons:commons-lang3:${apacheCommonVersion}" - compileOnly "org.projectlombok:lombok" developmentOnly "org.springframework.boot:spring-boot-devtools" annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" @@ -45,6 +29,3 @@ dependencies { testImplementation "io.projectreactor:reactor-test" } -tasks.named("test") { - useJUnitPlatform() -} diff --git a/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java b/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java index e9aafd1..44072d8 100644 --- a/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java +++ b/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java @@ -3,8 +3,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +@Enable @SpringBootApplication -public class BlogApplication { +public class DevtoolsApplication { public static void main(String[] args) { // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable From e1022d9692c4f1162b752db1e81a57f3ad40f71d Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 00:09:48 +0800 Subject: [PATCH 2/8] aes encryption --- build.gradle | 12 +- cloud.gradle | 122 ++++++++++++++++++ gradle.properties | 4 +- gradlew | 0 gradlew.bat | 92 +++++++++++++ .../heliannuuthus/blog/BlogApplication.java | 16 --- .../devtools/DevtoolsApplication.java | 16 +++ .../config/PropertiesConfiguration.java | 7 + .../devtools/config/SecuredConfiguration.java | 12 ++ .../devtools/controller/KeysController.java | 23 ++++ .../crypto/algorithms/OamAlgorithm.java | 9 ++ .../devtools/crypto/algorithms/Padding.java | 13 ++ .../devtools/crypto/asymmetric/Signer.java | 3 + .../devtools/crypto/asymmetric/Verifier.java | 3 + .../crypto/parameters/AESGCMParameters.java | 32 +++++ .../crypto/parameters/AESParameters.java | 74 +++++++++++ .../crypto/parameters/BlockParameters.java | 27 ++++ .../crypto/symmetric/BlockCipher.java | 30 +++++ .../devtools/exception/CryptoException.java | 19 +++ .../devtools/properties/KeyProperties.java | 6 + .../blog/BlogApplicationTests.java | 13 -- .../devtools/BlockCipherTest.java | 55 ++++++++ 22 files changed, 555 insertions(+), 33 deletions(-) create mode 100644 cloud.gradle mode change 100644 => 100755 gradlew create mode 100644 gradlew.bat delete mode 100644 src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/config/PropertiesConfiguration.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/config/SecuredConfiguration.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/controller/KeysController.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/OamAlgorithm.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/Padding.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Signer.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Verifier.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/symmetric/BlockCipher.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/exception/CryptoException.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/properties/KeyProperties.java delete mode 100644 src/test/java/io/ghcr/heliannuuthus/blog/BlogApplicationTests.java create mode 100644 src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java diff --git a/build.gradle b/build.gradle index 52876fb..086005c 100644 --- a/build.gradle +++ b/build.gradle @@ -3,12 +3,17 @@ plugins { id "org.springframework.boot" version "3.2.3" id "io.spring.dependency-management" version "1.1.4" id "org.springdoc.openapi-gradle-plugin" version "1.8.0" - id 'me.qoomon.git-versioning' version '6.4.2' + id "me.qoomon.git-versioning" version "6.4.2" id "com.diffplug.spotless" version "6.25.0" id "io.freefair.lombok" version "8.6" } -apply from: "https://raw.gitmirror.com/heliannuuthus/integrate-deploy/master/gradle/cloud.gradle" + +apply from: "./cloud.gradle" + +ext { + bcVersion = "1.77" +} repositories { maven { url "https://maven.aliyun.com/repository/public" } @@ -20,6 +25,9 @@ dependencies { implementation "org.springframework.boot:spring-boot-starter-data-r2dbc" implementation "org.springframework.boot:spring-boot-starter-webflux" + implementation "org.bouncycastle:bcprov-jdk18on:${bcVersion}" + implementation "org.bouncycastle:bcpkix-jdk18on:${bcVersion}" + compileOnly "org.projectlombok:lombok" developmentOnly "org.springframework.boot:spring-boot-devtools" annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" diff --git a/cloud.gradle b/cloud.gradle new file mode 100644 index 0000000..c2c086c --- /dev/null +++ b/cloud.gradle @@ -0,0 +1,122 @@ +buildscript { + repositories { + maven { url "https://maven.aliyun.com/repository/gradle-plugin" } + maven { url "https://repo.spring.io/plugins-snapshot" } + mavenCentral() + } + dependencies { + classpath "org.springframework.boot:spring-boot-gradle-plugin:3.2.3" + classpath "io.spring.gradle:dependency-management-plugin:1.1.4" + classpath "org.springdoc:springdoc-openapi-gradle-plugin:1.8.0" + classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" + classpath "me.qoomon:gradle-git-versioning-plugin:6.4.2" + classpath "io.freefair.gradle:lombok-plugin:8.6" + } +} + +ext { + r2dbcConnCompVersion = "2.1.8" + r2dbcSpiVersion = "1.0.0.RELEASE" + r2dbcPoolVersion = "1.0.0.RELEASE" + joseVersion = "0.9.2" + log4j2Version = "2.19.0" + guavaVersion = "31.1-jre" + hutoolVersion = "5.8.10" + springDocVersion = "2.0.2" + bootVersion = "3.0.1" + cloudVersion = "2022.0.0" + alibabaCloudVersion = "2022.0.0.0-RC1" + guavaVersion = "33.0.0-jre" + lang3Version = "3.14.0" + spotlessVersion = "1.21.0" + helianthusCommonVersion = "0.1.0-2f44836" +} + +sourceCompatibility = 17 +targetCompatibility = 17 + +gitVersioning.apply { + version = rootProject.findProperty("version") + refs { + branch('master') { + version = '${version}-${commit.short}' + } + branch('.+') { + version = '${version}-${commit.short}-SNAPSHOT' + } + } +} + +dependencies { + implementation "org.springframework.boot:spring-boot-starter-data-r2dbc" + implementation "org.springframework.boot:spring-boot-starter-validation" + implementation "org.springframework.boot:spring-boot-devtools" + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + testImplementation "org.springframework.boot:spring-boot-starter-test" + testImplementation "io.projectreactor:reactor-test" + + //apollo + implementation "io.ghrc:helianthus-annuus-apollo-client:${helianthusCommonVersion}" + + // spring cloud + implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery" + + + // utils + implementation "com.google.guava:guava:${guavaVersion}" + implementation "org.apache.commons:commons-lang3:${lang3Version}" + +} + +allprojects { + + apply plugin: "org.springframework.boot" + apply plugin: "io.spring.dependency-management" + apply plugin: "com.diffplug.spotless" + apply plugin: "io.freefair.lombok" + apply plugin: "me.qoomon.git-versioning" + + group "io.ghrc" + + configurations { + compileOnly { + extendsFrom annotationProcessor + } + all*.exclude module: "spring-boot-starter-logging" + } + + repositories { + maven { url "https://maven.aliyun.com/nexus/content/groups/public" } + maven { url "https://maven.aliyun.com/nexus/content/repositories/jcenter" } + maven { + name = "GitHubPackages" + url = "https://maven.pkg.github.com/heliannuuthus/${project.name}" + credentials { + username = rootProject.findProperty("gpr.user") ?: System.getenv("GPR_USER") + password = rootProject.findProperty("gpr.token") ?: System.getenv("GPR_TOKEN") + } + } + mavenCentral() + } + + tasks.named("test") { + useJUnitPlatform() + } + + dependencyManagement { + imports { + mavenBom "org.springframework.boot:spring-boot-dependencies:${bootVersion}" + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${cloudVersion}" + mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${alibabaCloudVersion}" + } + } + + spotless { + java { + importOrder() + removeUnusedImports() + googleJavaFormat("${spotlessVersion}").groupArtifact("com.google.googlejavaformat:google-java-format") + formatAnnotations() + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0f373ec..1ceb703 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -rootProject.name = 'helianthus-annuus-blog' -version = "0.0.1-SNAPSHOT" +group=io.ghrc +version=0.1.0 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java b/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java deleted file mode 100644 index 44072d8..0000000 --- a/src/main/java/io/ghcr/heliannuuthus/blog/BlogApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.ghcr.heliannuuthus.blog; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@Enable -@SpringBootApplication -public class DevtoolsApplication { - - public static void main(String[] args) { - // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable - System.setProperty("spring.devtools.restart.enabled", "false"); - SpringApplication.run(BlogApplication.class, args); - } - -} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java b/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java new file mode 100644 index 0000000..246e822 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java @@ -0,0 +1,16 @@ +package io.ghcr.heliannuuthus.devtools; + +import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableApolloConfig +@SpringBootApplication +public class DevtoolsApplication { + + public static void main(String[] args) { + // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable + System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(DevtoolsApplication.class, args); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/config/PropertiesConfiguration.java b/src/main/java/io/ghcr/heliannuuthus/devtools/config/PropertiesConfiguration.java new file mode 100644 index 0000000..fd04552 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/config/PropertiesConfiguration.java @@ -0,0 +1,7 @@ +package io.ghcr.heliannuuthus.devtools.config; + +import io.ghcr.heliannuuthus.devtools.properties.KeyProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@EnableConfigurationProperties(KeyProperties.class) +public class PropertiesConfiguration {} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/config/SecuredConfiguration.java b/src/main/java/io/ghcr/heliannuuthus/devtools/config/SecuredConfiguration.java new file mode 100644 index 0000000..29deaee --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/config/SecuredConfiguration.java @@ -0,0 +1,12 @@ +package io.ghcr.heliannuuthus.devtools.config; + +import java.security.Security; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SecuredConfiguration { + static { + Security.addProvider(new BouncyCastleProvider()); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/controller/KeysController.java b/src/main/java/io/ghcr/heliannuuthus/devtools/controller/KeysController.java new file mode 100644 index 0000000..47c520e --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/controller/KeysController.java @@ -0,0 +1,23 @@ +package io.ghcr.heliannuuthus.devtools.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@Slf4j +@RestController +@RequestMapping("/keys") +public class KeysController { + + @GetMapping("/asymmetric") + public Mono asymmetricKey() { + return Mono.just(""); + } + + @GetMapping("/symmetric") + public Mono symmetricKey() { + return Mono.just(""); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/OamAlgorithm.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/OamAlgorithm.java new file mode 100644 index 0000000..4ef3586 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/OamAlgorithm.java @@ -0,0 +1,9 @@ +package io.ghcr.heliannuuthus.devtools.crypto.algorithms; + +public interface OamAlgorithm { + + String AES_ALGORITHM = "AES"; + String RSA_ALGORITHM = "RSA"; + + String getAlgorithm(); +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/Padding.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/Padding.java new file mode 100644 index 0000000..8a49b4c --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/algorithms/Padding.java @@ -0,0 +1,13 @@ +package io.ghcr.heliannuuthus.devtools.crypto.algorithms; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Padding { + PKCS7("PKCS7Padding"), + PKCS5("PKCS5Padding"), + None("NoPadding"); + private final String name; +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Signer.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Signer.java new file mode 100644 index 0000000..0892b13 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Signer.java @@ -0,0 +1,3 @@ +package io.ghcr.heliannuuthus.devtools.crypto.asymmetric; + +public class Signer {} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Verifier.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Verifier.java new file mode 100644 index 0000000..d89328a --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/asymmetric/Verifier.java @@ -0,0 +1,3 @@ +package io.ghcr.heliannuuthus.devtools.crypto.asymmetric; + +public class Verifier {} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java new file mode 100644 index 0000000..db12474 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java @@ -0,0 +1,32 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; +import lombok.Getter; +import lombok.Setter; +import org.bouncycastle.jcajce.spec.AEADParameterSpec; + +@Getter +@Setter +public class AESGCMParameters extends AESParameters { + + private byte[] aad; + + public AESGCMParameters(byte[] key) { + this(key, generateIv(12)); + } + + public AESGCMParameters(byte[] key, byte[] iv) { + this(key, iv, null); + } + + public AESGCMParameters(byte[] key, byte[] iv, byte[] aad) { + super(key, iv, Padding.None, GCM_MODE); + this.aad = aad; + } + + @Override + public AlgorithmParameterSpec getSpec() { + return new AEADParameterSpec(getIv(), 128, aad); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java new file mode 100644 index 0000000..447fc09 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java @@ -0,0 +1,74 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters; + +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; +import java.util.random.RandomGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +public class AESParameters extends BlockParameters { + + public AESParameters(byte[] key, String encryptMode) { + this(key, generateIv(16), PKCS7, encryptMode); + } + + public AESParameters(byte[] key, Padding padding, String encryptMode) { + this(key, generateIv(16), padding, encryptMode); + } + + protected AESParameters(byte[] key, byte[] iv, Padding padding, String encryptMode) { + this.key = key; + this.iv = iv; + this.mode = encryptMode; + this.padding = padding; + } + + public static byte[] generateIv(int len) { + byte[] iv = new byte[len]; + RandomGenerator.getDefault().nextBytes(iv); + return iv; + } + + public static final String CBC_MODE = "CBC"; + public static final String GCM_MODE = "GCM"; + + private byte[] key; + + private byte[] iv; + + private Padding padding; + + private String mode; + + @Override + public String getName() { + return AES_ALGORITHM; + } + + @Override + public String getMode() { + return mode; + } + + @Override + public SecretKey getKey() { + return new SecretKeySpec(this.key, getName()); + } + + @Override + public AlgorithmParameterSpec getSpec() { + return new IvParameterSpec(iv); + } + + @Override + public Padding getPadding() { + return this.padding; + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java new file mode 100644 index 0000000..2080a54 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java @@ -0,0 +1,27 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm; +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; +import javax.crypto.SecretKey; +import org.apache.commons.lang3.StringUtils; + +public abstract class BlockParameters implements OamAlgorithm { + + @Override + public String getAlgorithm() { + return StringUtils.joinWith("/", getName(), getMode(), getPadding().getName()); + } + + public abstract String getName(); + + public abstract String getMode(); + + public Padding getPadding() { + return Padding.PKCS7; + } + + public abstract SecretKey getKey(); + + public abstract AlgorithmParameterSpec getSpec(); +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/symmetric/BlockCipher.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/symmetric/BlockCipher.java new file mode 100644 index 0000000..8c640f1 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/symmetric/BlockCipher.java @@ -0,0 +1,30 @@ +package io.ghcr.heliannuuthus.devtools.crypto.symmetric; + +import io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters; +import io.ghcr.heliannuuthus.devtools.exception.CryptoException; +import javax.crypto.Cipher; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +public class BlockCipher { + public byte[] encrypt(byte[] plaintext, BlockParameters parameters) { + try { + Cipher cipher = + Cipher.getInstance(parameters.getAlgorithm(), BouncyCastleProvider.PROVIDER_NAME); + cipher.init(Cipher.ENCRYPT_MODE, parameters.getKey(), parameters.getSpec()); + return cipher.doFinal(plaintext); + } catch (Exception e) { + throw new CryptoException(Cipher.ENCRYPT_MODE, parameters.getAlgorithm(), e); + } + } + + public byte[] decrypt(byte[] cypher, BlockParameters parameters) { + try { + Cipher cipher = + Cipher.getInstance(parameters.getAlgorithm(), BouncyCastleProvider.PROVIDER_NAME); + cipher.init(Cipher.DECRYPT_MODE, parameters.getKey(), parameters.getSpec()); + return cipher.doFinal(cypher); + } catch (Exception e) { + throw new CryptoException(Cipher.DECRYPT_MODE, parameters.getAlgorithm(), e); + } + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/exception/CryptoException.java b/src/main/java/io/ghcr/heliannuuthus/devtools/exception/CryptoException.java new file mode 100644 index 0000000..206efa5 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/exception/CryptoException.java @@ -0,0 +1,19 @@ +package io.ghcr.heliannuuthus.devtools.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +public class CryptoException extends ResponseStatusException { + + public CryptoException(int mode, String algorithm) { + super( + HttpStatus.UNPROCESSABLE_ENTITY, String.format("mode: %d, algorithm: %s", mode, algorithm)); + } + + public CryptoException(int mode, String algorithm, Throwable cause) { + super( + HttpStatus.UNPROCESSABLE_ENTITY, + String.format("mode: %d, algorithm: %s", mode, algorithm), + cause); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/properties/KeyProperties.java b/src/main/java/io/ghcr/heliannuuthus/devtools/properties/KeyProperties.java new file mode 100644 index 0000000..1492bee --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/properties/KeyProperties.java @@ -0,0 +1,6 @@ +package io.ghcr.heliannuuthus.devtools.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("oam.devtool.crypto") +public class KeyProperties {} diff --git a/src/test/java/io/ghcr/heliannuuthus/blog/BlogApplicationTests.java b/src/test/java/io/ghcr/heliannuuthus/blog/BlogApplicationTests.java deleted file mode 100644 index f40afc4..0000000 --- a/src/test/java/io/ghcr/heliannuuthus/blog/BlogApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.ghcr.heliannuuthus.blog; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class BlogApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java new file mode 100644 index 0000000..a725d9a --- /dev/null +++ b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java @@ -0,0 +1,55 @@ +package io.ghcr.heliannuuthus.devtools; + +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm.AES_ALGORITHM; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.AESParameters.*; + +import io.ghcr.heliannuuthus.devtools.crypto.parameters.AESGCMParameters; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.AESParameters; +import io.ghcr.heliannuuthus.devtools.crypto.symmetric.BlockCipher; +import java.security.NoSuchAlgorithmException; +import java.security.Security; +import java.util.Objects; +import java.util.stream.Stream; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class BlockCipherTest { + + private static final BlockCipher blockCipher = new BlockCipher(); + + @BeforeAll + static void init() { + Security.addProvider(new BouncyCastleProvider()); + } + + static Stream buildAESCipherParameters() { + return Stream.of(CBC_MODE, GCM_MODE) + .flatMap(mode -> Stream.of(128, 192, 256).map(size -> Arguments.of(mode, size))); + } + + @ParameterizedTest + @MethodSource("buildAESCipherParameters") + @DisplayName("test AES CBC encryption") + void testAESCBCEncryption(String mode, int size) throws NoSuchAlgorithmException { + byte[] plaintext = "plaintext".getBytes(); + KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); + keyGenerator.init(size); + SecretKey secretKey = keyGenerator.generateKey(); + AESParameters aesParameters = + Objects.equals(GCM_MODE, mode) + ? new AESGCMParameters(secretKey.getEncoded(), generateIv(12), generateIv(128)) + : new AESParameters(secretKey.getEncoded(), mode); + byte[] cipher = blockCipher.encrypt(plaintext, aesParameters); + Assertions.assertArrayEquals(plaintext, blockCipher.decrypt(cipher, aesParameters)); + } +} From 0834a02a1eb569d24e7715cfae98b4eebc1d0e77 Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 11:10:06 +0800 Subject: [PATCH 3/8] aes ecb encryption --- cloud.gradle | 6 +- .../crypto/parameters/AESGCMParameters.java | 32 ------- .../crypto/parameters/AESParameters.java | 74 --------------- .../crypto/parameters/BlockParameters.java | 45 +++++++--- .../crypto/parameters/ECBParameters.java | 9 ++ .../parameters/aes/AESCBCParameters.java | 44 +++++++++ .../parameters/aes/AESECBParameters.java | 35 ++++++++ .../parameters/aes/AESGCMParameters.java | 41 +++++++++ .../devtools/utils/CryptoUtils.java | 17 ++++ .../devtools/BlockCipherTest.java | 90 +++++++++++-------- 10 files changed, 234 insertions(+), 159 deletions(-) delete mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java delete mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java diff --git a/cloud.gradle b/cloud.gradle index c2c086c..1f44745 100644 --- a/cloud.gradle +++ b/cloud.gradle @@ -28,6 +28,7 @@ ext { alibabaCloudVersion = "2022.0.0.0-RC1" guavaVersion = "33.0.0-jre" lang3Version = "3.14.0" + rngVersion = "1.5" spotlessVersion = "1.21.0" helianthusCommonVersion = "0.1.0-2f44836" } @@ -38,10 +39,10 @@ targetCompatibility = 17 gitVersioning.apply { version = rootProject.findProperty("version") refs { - branch('master') { + branch("master") { version = '${version}-${commit.short}' } - branch('.+') { + branch(".+") { version = '${version}-${commit.short}-SNAPSHOT' } } @@ -65,6 +66,7 @@ dependencies { // utils implementation "com.google.guava:guava:${guavaVersion}" implementation "org.apache.commons:commons-lang3:${lang3Version}" + implementation "org.apache.commons:commons-rng-simple:${rngVersion}" } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java deleted file mode 100644 index db12474..0000000 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESGCMParameters.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.ghcr.heliannuuthus.devtools.crypto.parameters; - -import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; -import java.security.spec.AlgorithmParameterSpec; -import lombok.Getter; -import lombok.Setter; -import org.bouncycastle.jcajce.spec.AEADParameterSpec; - -@Getter -@Setter -public class AESGCMParameters extends AESParameters { - - private byte[] aad; - - public AESGCMParameters(byte[] key) { - this(key, generateIv(12)); - } - - public AESGCMParameters(byte[] key, byte[] iv) { - this(key, iv, null); - } - - public AESGCMParameters(byte[] key, byte[] iv, byte[] aad) { - super(key, iv, Padding.None, GCM_MODE); - this.aad = aad; - } - - @Override - public AlgorithmParameterSpec getSpec() { - return new AEADParameterSpec(getIv(), 128, aad); - } -} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java deleted file mode 100644 index 447fc09..0000000 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/AESParameters.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.ghcr.heliannuuthus.devtools.crypto.parameters; - -import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; - -import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; -import java.security.spec.AlgorithmParameterSpec; -import java.util.random.RandomGenerator; -import javax.crypto.SecretKey; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -public class AESParameters extends BlockParameters { - - public AESParameters(byte[] key, String encryptMode) { - this(key, generateIv(16), PKCS7, encryptMode); - } - - public AESParameters(byte[] key, Padding padding, String encryptMode) { - this(key, generateIv(16), padding, encryptMode); - } - - protected AESParameters(byte[] key, byte[] iv, Padding padding, String encryptMode) { - this.key = key; - this.iv = iv; - this.mode = encryptMode; - this.padding = padding; - } - - public static byte[] generateIv(int len) { - byte[] iv = new byte[len]; - RandomGenerator.getDefault().nextBytes(iv); - return iv; - } - - public static final String CBC_MODE = "CBC"; - public static final String GCM_MODE = "GCM"; - - private byte[] key; - - private byte[] iv; - - private Padding padding; - - private String mode; - - @Override - public String getName() { - return AES_ALGORITHM; - } - - @Override - public String getMode() { - return mode; - } - - @Override - public SecretKey getKey() { - return new SecretKeySpec(this.key, getName()); - } - - @Override - public AlgorithmParameterSpec getSpec() { - return new IvParameterSpec(iv); - } - - @Override - public Padding getPadding() { - return this.padding; - } -} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java index 2080a54..6dbeba3 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java @@ -2,26 +2,45 @@ import io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm; import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; -import java.security.spec.AlgorithmParameterSpec; -import javax.crypto.SecretKey; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.lang3.StringUtils; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.security.spec.AlgorithmParameterSpec; + +@Setter +@Getter public abstract class BlockParameters implements OamAlgorithm { - @Override - public String getAlgorithm() { - return StringUtils.joinWith("/", getName(), getMode(), getPadding().getName()); - } + public static final String ECB_MODE = "ECB"; + public static final String CBC_MODE = "CBC"; + public static final String GCM_MODE = "GCM"; + + protected byte[] key; + + @Override + public String getAlgorithm() { + return StringUtils.joinWith("/", getName(), getMode(), getPadding().getName()); + } + + public String getName() { + return null; + } - public abstract String getName(); + public abstract String getMode(); - public abstract String getMode(); - public Padding getPadding() { - return Padding.PKCS7; - } + public Padding getPadding() { + return Padding.PKCS7; + } - public abstract SecretKey getKey(); + public SecretKey getKey() { + return new SecretKeySpec(this.key, getName()); + } - public abstract AlgorithmParameterSpec getSpec(); + public AlgorithmParameterSpec getSpec() { + return null; + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java new file mode 100644 index 0000000..836047e --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java @@ -0,0 +1,9 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters; + +public class ECBParameters extends BlockParameters { + + @Override + public String getMode() { + return ECB_MODE; + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java new file mode 100644 index 0000000..a0bd071 --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java @@ -0,0 +1,44 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import javax.crypto.spec.IvParameterSpec; +import java.security.spec.AlgorithmParameterSpec; + +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; +import static org.apache.commons.lang3.RandomUtils.nextBytes; + + +@Setter +@Getter +@ToString +public class AESCBCParameters extends AESECBParameters { + + public AESCBCParameters(byte[] key) { + this(key, nextBytes(16), PKCS7); + } + + public AESCBCParameters(byte[] key, Padding padding) { + this(key, nextBytes(16), padding); + } + + protected AESCBCParameters(byte[] key, byte[] iv, Padding padding) { + super(key, padding); + this.iv = iv; + } + + private byte[] iv; + + @Override + public String getMode() { + return CBC_MODE; + } + + @Override + public AlgorithmParameterSpec getSpec() { + return new IvParameterSpec(iv); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java new file mode 100644 index 0000000..a9f228f --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java @@ -0,0 +1,35 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.ECBParameters; +import lombok.Getter; + +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; + + +@Getter +public class AESECBParameters extends ECBParameters { + + public AESECBParameters(byte[] key) { + this(key, PKCS7); + } + + protected AESECBParameters(byte[] key, Padding padding) { + this.key = key; + this.padding = padding; + } + + + private final Padding padding; + + @Override + public String getName() { + return AES_ALGORITHM; + } + + + @Override + public Padding getPadding() { + return this.padding; + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java new file mode 100644 index 0000000..1d415cc --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java @@ -0,0 +1,41 @@ +package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; + +import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import lombok.Getter; +import lombok.Setter; +import org.bouncycastle.jcajce.spec.AEADParameterSpec; + +import java.security.spec.AlgorithmParameterSpec; + +import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; + + +@Getter +@Setter +public class AESGCMParameters extends AESCBCParameters { + + private byte[] aad; + + public AESGCMParameters(byte[] key) { + this(key, nextBytes(12)); + } + + public AESGCMParameters(byte[] key, byte[] iv) { + this(key, iv, null); + } + + public AESGCMParameters(byte[] key, byte[] iv, byte[] aad) { + super(key, iv, Padding.None); + this.aad = aad; + } + + @Override + public String getMode() { + return GCM_MODE; + } + + @Override + public AlgorithmParameterSpec getSpec() { + return new AEADParameterSpec(getIv(), 128, aad); + } +} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java b/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java new file mode 100644 index 0000000..ec6bcaf --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java @@ -0,0 +1,17 @@ +package io.ghcr.heliannuuthus.devtools.utils; + +import lombok.experimental.UtilityClass; +import org.apache.commons.rng.UniformRandomProvider; +import org.apache.commons.rng.simple.RandomSource; + +@UtilityClass +public class CryptoUtils { + private static final UniformRandomProvider UNIFORM_RANDOM_PROVIDER = RandomSource.MT_64.create(); + + public static byte[] nextBytes(int len) { + byte[] iv = new byte[len]; + UNIFORM_RANDOM_PROVIDER.nextBytes(iv); + return iv; + } + +} diff --git a/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java index a725d9a..0283e90 100644 --- a/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java +++ b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java @@ -1,17 +1,10 @@ package io.ghcr.heliannuuthus.devtools; -import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm.AES_ALGORITHM; -import static io.ghcr.heliannuuthus.devtools.crypto.parameters.AESParameters.*; - -import io.ghcr.heliannuuthus.devtools.crypto.parameters.AESGCMParameters; -import io.ghcr.heliannuuthus.devtools.crypto.parameters.AESParameters; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESECBParameters; +import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESGCMParameters; import io.ghcr.heliannuuthus.devtools.crypto.symmetric.BlockCipher; -import java.security.NoSuchAlgorithmException; -import java.security.Security; -import java.util.Objects; -import java.util.stream.Stream; -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKey; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -22,34 +15,55 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.junit.jupiter.MockitoExtension; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import java.security.NoSuchAlgorithmException; +import java.security.Security; +import java.util.stream.Stream; + +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm.AES_ALGORITHM; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters.ECB_MODE; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.CBC_MODE; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.GCM_MODE; +import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; + @ExtendWith(MockitoExtension.class) class BlockCipherTest { - private static final BlockCipher blockCipher = new BlockCipher(); - - @BeforeAll - static void init() { - Security.addProvider(new BouncyCastleProvider()); - } - - static Stream buildAESCipherParameters() { - return Stream.of(CBC_MODE, GCM_MODE) - .flatMap(mode -> Stream.of(128, 192, 256).map(size -> Arguments.of(mode, size))); - } - - @ParameterizedTest - @MethodSource("buildAESCipherParameters") - @DisplayName("test AES CBC encryption") - void testAESCBCEncryption(String mode, int size) throws NoSuchAlgorithmException { - byte[] plaintext = "plaintext".getBytes(); - KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); - keyGenerator.init(size); - SecretKey secretKey = keyGenerator.generateKey(); - AESParameters aesParameters = - Objects.equals(GCM_MODE, mode) - ? new AESGCMParameters(secretKey.getEncoded(), generateIv(12), generateIv(128)) - : new AESParameters(secretKey.getEncoded(), mode); - byte[] cipher = blockCipher.encrypt(plaintext, aesParameters); - Assertions.assertArrayEquals(plaintext, blockCipher.decrypt(cipher, aesParameters)); - } + private static final BlockCipher blockCipher = new BlockCipher(); + + @BeforeAll + static void init() { + Security.addProvider(new BouncyCastleProvider()); + } + + static Stream buildAESCipherParameters() { + return Stream.of(CBC_MODE, GCM_MODE, ECB_MODE) + .flatMap(mode -> Stream.of(128, 192, 256).map(size -> Arguments.of(mode, size))); + } + + @ParameterizedTest + @MethodSource("buildAESCipherParameters") + @DisplayName("test AES CBC encryption") + void testAESCBCEncryption(String mode, int size) throws NoSuchAlgorithmException { + byte[] plaintext = "plaintext".getBytes(); + KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); + keyGenerator.init(size); + SecretKey secretKey = keyGenerator.generateKey(); + BlockParameters blockParameters; + switch (mode) { + case ECB_MODE -> { + blockParameters = new AESECBParameters(secretKey.getEncoded()); + } + case CBC_MODE -> { + blockParameters = new AESCBCParameters(secretKey.getEncoded()); + } + case GCM_MODE -> { + blockParameters = new AESGCMParameters(secretKey.getEncoded(), nextBytes(12), nextBytes(128)); + } + default -> throw new UnsupportedOperationException(); + } + byte[] cipher = blockCipher.encrypt(plaintext, blockParameters); + Assertions.assertArrayEquals(plaintext, blockCipher.decrypt(cipher, blockParameters)); + } } From 8e0765db631827a135c3b6f225df4beed8ea3ec1 Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 11:10:34 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=8E=A8=20Aes=20ecb=20encryption?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crypto/parameters/BlockParameters.java | 50 +++++------ .../crypto/parameters/ECBParameters.java | 8 +- .../parameters/aes/AESCBCParameters.java | 50 +++++------ .../parameters/aes/AESECBParameters.java | 39 ++++---- .../parameters/aes/AESGCMParameters.java | 46 +++++----- .../devtools/utils/CryptoUtils.java | 13 ++- .../devtools/BlockCipherTest.java | 88 +++++++++---------- 7 files changed, 142 insertions(+), 152 deletions(-) diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java index 6dbeba3..e3f40df 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/BlockParameters.java @@ -2,45 +2,43 @@ import io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm; import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; import lombok.Getter; import lombok.Setter; import org.apache.commons.lang3.StringUtils; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; -import java.security.spec.AlgorithmParameterSpec; - @Setter @Getter public abstract class BlockParameters implements OamAlgorithm { - public static final String ECB_MODE = "ECB"; - public static final String CBC_MODE = "CBC"; - public static final String GCM_MODE = "GCM"; - - protected byte[] key; + public static final String ECB_MODE = "ECB"; + public static final String CBC_MODE = "CBC"; + public static final String GCM_MODE = "GCM"; - @Override - public String getAlgorithm() { - return StringUtils.joinWith("/", getName(), getMode(), getPadding().getName()); - } + protected byte[] key; - public String getName() { - return null; - } + @Override + public String getAlgorithm() { + return StringUtils.joinWith("/", getName(), getMode(), getPadding().getName()); + } - public abstract String getMode(); + public String getName() { + return null; + } + public abstract String getMode(); - public Padding getPadding() { - return Padding.PKCS7; - } + public Padding getPadding() { + return Padding.PKCS7; + } - public SecretKey getKey() { - return new SecretKeySpec(this.key, getName()); - } + public SecretKey getKey() { + return new SecretKeySpec(this.key, getName()); + } - public AlgorithmParameterSpec getSpec() { - return null; - } + public AlgorithmParameterSpec getSpec() { + return null; + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java index 836047e..7147574 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/ECBParameters.java @@ -2,8 +2,8 @@ public class ECBParameters extends BlockParameters { - @Override - public String getMode() { - return ECB_MODE; - } + @Override + public String getMode() { + return ECB_MODE; + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java index a0bd071..f4f58bd 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESCBCParameters.java @@ -1,44 +1,42 @@ package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; +import static org.apache.commons.lang3.RandomUtils.nextBytes; + import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; +import javax.crypto.spec.IvParameterSpec; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import javax.crypto.spec.IvParameterSpec; -import java.security.spec.AlgorithmParameterSpec; - -import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; -import static org.apache.commons.lang3.RandomUtils.nextBytes; - - @Setter @Getter @ToString public class AESCBCParameters extends AESECBParameters { - public AESCBCParameters(byte[] key) { - this(key, nextBytes(16), PKCS7); - } + public AESCBCParameters(byte[] key) { + this(key, nextBytes(16), PKCS7); + } - public AESCBCParameters(byte[] key, Padding padding) { - this(key, nextBytes(16), padding); - } + public AESCBCParameters(byte[] key, Padding padding) { + this(key, nextBytes(16), padding); + } - protected AESCBCParameters(byte[] key, byte[] iv, Padding padding) { - super(key, padding); - this.iv = iv; - } + protected AESCBCParameters(byte[] key, byte[] iv, Padding padding) { + super(key, padding); + this.iv = iv; + } - private byte[] iv; + private byte[] iv; - @Override - public String getMode() { - return CBC_MODE; - } + @Override + public String getMode() { + return CBC_MODE; + } - @Override - public AlgorithmParameterSpec getSpec() { - return new IvParameterSpec(iv); - } + @Override + public AlgorithmParameterSpec getSpec() { + return new IvParameterSpec(iv); + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java index a9f228f..3f7b8c2 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESECBParameters.java @@ -1,35 +1,32 @@ package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; + import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; import io.ghcr.heliannuuthus.devtools.crypto.parameters.ECBParameters; import lombok.Getter; -import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding.PKCS7; - - @Getter public class AESECBParameters extends ECBParameters { - public AESECBParameters(byte[] key) { - this(key, PKCS7); - } - - protected AESECBParameters(byte[] key, Padding padding) { - this.key = key; - this.padding = padding; - } - + public AESECBParameters(byte[] key) { + this(key, PKCS7); + } - private final Padding padding; + protected AESECBParameters(byte[] key, Padding padding) { + this.key = key; + this.padding = padding; + } - @Override - public String getName() { - return AES_ALGORITHM; - } + private final Padding padding; + @Override + public String getName() { + return AES_ALGORITHM; + } - @Override - public Padding getPadding() { - return this.padding; - } + @Override + public Padding getPadding() { + return this.padding; + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java index 1d415cc..9eb8e61 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/crypto/parameters/aes/AESGCMParameters.java @@ -1,41 +1,39 @@ package io.ghcr.heliannuuthus.devtools.crypto.parameters.aes; +import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; + import io.ghcr.heliannuuthus.devtools.crypto.algorithms.Padding; +import java.security.spec.AlgorithmParameterSpec; import lombok.Getter; import lombok.Setter; import org.bouncycastle.jcajce.spec.AEADParameterSpec; -import java.security.spec.AlgorithmParameterSpec; - -import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; - - @Getter @Setter public class AESGCMParameters extends AESCBCParameters { - private byte[] aad; + private byte[] aad; - public AESGCMParameters(byte[] key) { - this(key, nextBytes(12)); - } + public AESGCMParameters(byte[] key) { + this(key, nextBytes(12)); + } - public AESGCMParameters(byte[] key, byte[] iv) { - this(key, iv, null); - } + public AESGCMParameters(byte[] key, byte[] iv) { + this(key, iv, null); + } - public AESGCMParameters(byte[] key, byte[] iv, byte[] aad) { - super(key, iv, Padding.None); - this.aad = aad; - } + public AESGCMParameters(byte[] key, byte[] iv, byte[] aad) { + super(key, iv, Padding.None); + this.aad = aad; + } - @Override - public String getMode() { - return GCM_MODE; - } + @Override + public String getMode() { + return GCM_MODE; + } - @Override - public AlgorithmParameterSpec getSpec() { - return new AEADParameterSpec(getIv(), 128, aad); - } + @Override + public AlgorithmParameterSpec getSpec() { + return new AEADParameterSpec(getIv(), 128, aad); + } } diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java b/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java index ec6bcaf..5a6a473 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/utils/CryptoUtils.java @@ -6,12 +6,11 @@ @UtilityClass public class CryptoUtils { - private static final UniformRandomProvider UNIFORM_RANDOM_PROVIDER = RandomSource.MT_64.create(); - - public static byte[] nextBytes(int len) { - byte[] iv = new byte[len]; - UNIFORM_RANDOM_PROVIDER.nextBytes(iv); - return iv; - } + private static final UniformRandomProvider UNIFORM_RANDOM_PROVIDER = RandomSource.MT_64.create(); + public static byte[] nextBytes(int len) { + byte[] iv = new byte[len]; + UNIFORM_RANDOM_PROVIDER.nextBytes(iv); + return iv; + } } diff --git a/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java index 0283e90..9bbb760 100644 --- a/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java +++ b/src/test/java/io/ghcr/heliannuuthus/devtools/BlockCipherTest.java @@ -1,10 +1,21 @@ package io.ghcr.heliannuuthus.devtools; +import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm.AES_ALGORITHM; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters.ECB_MODE; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.CBC_MODE; +import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.GCM_MODE; +import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; + import io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters; import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters; import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESECBParameters; import io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESGCMParameters; import io.ghcr.heliannuuthus.devtools.crypto.symmetric.BlockCipher; +import java.security.NoSuchAlgorithmException; +import java.security.Security; +import java.util.stream.Stream; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -15,55 +26,44 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.junit.jupiter.MockitoExtension; -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKey; -import java.security.NoSuchAlgorithmException; -import java.security.Security; -import java.util.stream.Stream; - -import static io.ghcr.heliannuuthus.devtools.crypto.algorithms.OamAlgorithm.AES_ALGORITHM; -import static io.ghcr.heliannuuthus.devtools.crypto.parameters.BlockParameters.ECB_MODE; -import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.CBC_MODE; -import static io.ghcr.heliannuuthus.devtools.crypto.parameters.aes.AESCBCParameters.GCM_MODE; -import static io.ghcr.heliannuuthus.devtools.utils.CryptoUtils.nextBytes; - @ExtendWith(MockitoExtension.class) class BlockCipherTest { - private static final BlockCipher blockCipher = new BlockCipher(); + private static final BlockCipher blockCipher = new BlockCipher(); - @BeforeAll - static void init() { - Security.addProvider(new BouncyCastleProvider()); - } + @BeforeAll + static void init() { + Security.addProvider(new BouncyCastleProvider()); + } - static Stream buildAESCipherParameters() { - return Stream.of(CBC_MODE, GCM_MODE, ECB_MODE) - .flatMap(mode -> Stream.of(128, 192, 256).map(size -> Arguments.of(mode, size))); - } + static Stream buildAESCipherParameters() { + return Stream.of(CBC_MODE, GCM_MODE, ECB_MODE) + .flatMap(mode -> Stream.of(128, 192, 256).map(size -> Arguments.of(mode, size))); + } - @ParameterizedTest - @MethodSource("buildAESCipherParameters") - @DisplayName("test AES CBC encryption") - void testAESCBCEncryption(String mode, int size) throws NoSuchAlgorithmException { - byte[] plaintext = "plaintext".getBytes(); - KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); - keyGenerator.init(size); - SecretKey secretKey = keyGenerator.generateKey(); - BlockParameters blockParameters; - switch (mode) { - case ECB_MODE -> { - blockParameters = new AESECBParameters(secretKey.getEncoded()); - } - case CBC_MODE -> { - blockParameters = new AESCBCParameters(secretKey.getEncoded()); - } - case GCM_MODE -> { - blockParameters = new AESGCMParameters(secretKey.getEncoded(), nextBytes(12), nextBytes(128)); - } - default -> throw new UnsupportedOperationException(); - } - byte[] cipher = blockCipher.encrypt(plaintext, blockParameters); - Assertions.assertArrayEquals(plaintext, blockCipher.decrypt(cipher, blockParameters)); + @ParameterizedTest + @MethodSource("buildAESCipherParameters") + @DisplayName("test AES CBC encryption") + void testAESCBCEncryption(String mode, int size) throws NoSuchAlgorithmException { + byte[] plaintext = "plaintext".getBytes(); + KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); + keyGenerator.init(size); + SecretKey secretKey = keyGenerator.generateKey(); + BlockParameters blockParameters; + switch (mode) { + case ECB_MODE -> { + blockParameters = new AESECBParameters(secretKey.getEncoded()); + } + case CBC_MODE -> { + blockParameters = new AESCBCParameters(secretKey.getEncoded()); + } + case GCM_MODE -> { + blockParameters = + new AESGCMParameters(secretKey.getEncoded(), nextBytes(12), nextBytes(128)); + } + default -> throw new UnsupportedOperationException(); } + byte[] cipher = blockCipher.encrypt(plaintext, blockParameters); + Assertions.assertArrayEquals(plaintext, blockCipher.decrypt(cipher, blockParameters)); + } } From d331f315b14dbe926a65373a642e947e63f65558 Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 12:53:16 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=91=B7=20Ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflow/ci.yaml | 28 +++++++++++++++++++ cloud.gradle | 4 +++ .../devtools/DevtoolsApplication.java | 16 ----------- .../devtools/RuntimeApplication.java | 16 +++++++++++ 4 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 .github/workflow/ci.yaml delete mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java create mode 100644 src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java diff --git a/.github/workflow/ci.yaml b/.github/workflow/ci.yaml new file mode 100644 index 0000000..085df16 --- /dev/null +++ b/.github/workflow/ci.yaml @@ -0,0 +1,28 @@ +name: ci + +on: + pull_request: + types: [ opened, reopened, synchronize ] + pull_request_target: + types: [ closed ] + +jobs: + lint: + if: ${{ github.event.pull_request.merged != true }} + uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-lint.yml + + build: + if: always() + needs: lint + uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-build.yml + + containerize: + if: ${{ always() && github.event.pull_request.merged == true }} + needs: build + permissions: + contents: read + packages: write + uses: heliannuuthus/integrate-deploy/.github/workflows/call-containerize.yml + with: + version: ${{ needs.build.outputs.version }} + target: "./build" \ No newline at end of file diff --git a/cloud.gradle b/cloud.gradle index 1f44745..5d499fa 100644 --- a/cloud.gradle +++ b/cloud.gradle @@ -121,4 +121,8 @@ allprojects { formatAnnotations() } } +} + +bootJar { + archiveFileName = "app.${archiveExtension.get()}" } \ No newline at end of file diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java b/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java deleted file mode 100644 index 246e822..0000000 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/DevtoolsApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.ghcr.heliannuuthus.devtools; - -import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@EnableApolloConfig -@SpringBootApplication -public class DevtoolsApplication { - - public static void main(String[] args) { - // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable - System.setProperty("spring.devtools.restart.enabled", "false"); - SpringApplication.run(DevtoolsApplication.class, args); - } -} diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java b/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java new file mode 100644 index 0000000..f7fcdfd --- /dev/null +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java @@ -0,0 +1,16 @@ +package io.ghcr.heliannuuthus.devtools; + +import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableApolloConfig +@SpringBootApplication +public class RuntimeApplication { + + public static void main(String[] args) { + // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable + System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(RuntimeApplication.class, args); + } +} From 17bef5168b8c6357e4cf67db22e149ce442f5fd6 Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 12:54:08 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=91=B7=20Ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/{workflow => workflows}/ci.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/ci.yaml (100%) diff --git a/.github/workflow/ci.yaml b/.github/workflows/ci.yaml similarity index 100% rename from .github/workflow/ci.yaml rename to .github/workflows/ci.yaml From 47acffdd5f752efe1dda23b12060322e7709c5e6 Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 12:55:33 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=91=B7=20Ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 085df16..d0b970e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,12 +9,12 @@ on: jobs: lint: if: ${{ github.event.pull_request.merged != true }} - uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-lint.yml + uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-lint.yml@master build: if: always() needs: lint - uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-build.yml + uses: heliannuuthus/integrate-deploy/.github/workflows/call-gradle-build.yml@master containerize: if: ${{ always() && github.event.pull_request.merged == true }} @@ -22,7 +22,7 @@ jobs: permissions: contents: read packages: write - uses: heliannuuthus/integrate-deploy/.github/workflows/call-containerize.yml + uses: heliannuuthus/integrate-deploy/.github/workflows/call-containerize.yml@master with: version: ${{ needs.build.outputs.version }} target: "./build" \ No newline at end of file From 376143aea2d2609a3906ea4ecffb9a1ca6fee95b Mon Sep 17 00:00:00 2001 From: heliannuuthus Date: Sun, 17 Mar 2024 12:59:10 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=8E=A8=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heliannuuthus/devtools/RuntimeApplication.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java b/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java index f7fcdfd..e85bdad 100644 --- a/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java +++ b/src/main/java/io/ghcr/heliannuuthus/devtools/RuntimeApplication.java @@ -8,9 +8,9 @@ @SpringBootApplication public class RuntimeApplication { - public static void main(String[] args) { - // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable - System.setProperty("spring.devtools.restart.enabled", "false"); - SpringApplication.run(RuntimeApplication.class, args); - } + public static void main(String[] args) { + // https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable + System.setProperty("spring.devtools.restart.enabled", "false"); + SpringApplication.run(RuntimeApplication.class, args); + } }