add
All checks were successful
Gitea Actions Build / Build (push) Successful in 5m36s

This commit is contained in:
Armamem0t 2025-09-14 10:51:42 +08:00
parent 56080634c7
commit d991b4077b
6 changed files with 85 additions and 1 deletions

View File

@ -144,6 +144,9 @@ tasks.withType<org.gradle.jvm.tasks.Jar> {
}
repositories {
maven {
url = uri("https://maven.aliyun.com/repository/public/")
}
mavenCentral()
}

View File

@ -21,7 +21,7 @@
#
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-1-bin.zip
distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.14-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

View File

@ -47,6 +47,16 @@ public class OsPath implements Path {
return new OsPath(path);
}
public static OsPath of(URI uri) {
return new OsPath(Paths.get(uri));
}
public static OsPath of(File file) {
return new OsPath(file.toPath());
}
public static OsPath getCwd(){
return new OsPath(Paths.get(""));
}
@Override
public @NotNull FileSystem getFileSystem() {
return path.getFileSystem();

View File

@ -24,9 +24,12 @@
package com.mingliqiye.utils
import com.mingliqiye.utils.path.OsPath
import com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
fun main() {
AutoConfiguration.printBanner()
val path = OsPath.getCwd()
println(path.toAbsolutePath())
}

View File

@ -0,0 +1,35 @@
@file:JvmName("AesUtils")
package com.mingliqiye.utils.security
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
const val ALGORITHM = "AES"
const val AES_GCM_NO_PADDING = "AES/GCM/NoPadding"
const val AES_GCM_NO_PADDING_IV_LENGTH = 12
const val AES_GCM_NO_PADDING_TAG_LENGTH = 16
fun encryptAesGcmNoPadding(src: ByteArray, key: ByteArray,iv: ByteArray): ByteArray {
val secretKeySpec = createSecretKeySpec(ALGORITHM,key)
val cipher = Cipher.getInstance(AES_GCM_NO_PADDING)
val gcmParameterSpec = GCMParameterSpec(
AES_GCM_NO_PADDING_TAG_LENGTH * 8,
iv
)
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, gcmParameterSpec)
return cipher.doFinal(src)
}
fun encryptAesGcmNoPadding(src: ByteArray, key: String,iv: ByteArray): ByteArray {
return encryptAesGcmNoPadding(src, key.toByteArray(), iv)
}
fun encryptAesGcmNoPadding(src: String, key: String,iv: ByteArray): ByteArray {
return encryptAesGcmNoPadding(src.toByteArray(), key.toByteArray(), iv)
}
fun main() {
val iv = getRandomBytes(16)
println(encryptAesGcmNoPadding("mingliqiye","key", iv))
}

View File

@ -0,0 +1,33 @@
@file:JvmName("SecureUtils")
package com.mingliqiye.utils.security
import java.security.MessageDigest
import java.security.SecureRandom
import javax.crypto.SecretKey
import javax.crypto.spec.SecretKeySpec
internal val SECURE_RANDOM = SecureRandom()
fun getRandomBytes(length: Int): ByteArray {
val bytes = ByteArray(length)
SECURE_RANDOM.nextBytes(bytes)
return bytes
}
fun createSecretKey(algorithm: String, data: ByteArray): ByteArray {
val md = MessageDigest.getInstance(algorithm)
return md.digest(data)
}
fun createSecretKey(algorithm: String, data: String): ByteArray {
return createSecretKey(algorithm, data.toByteArray())
}
fun createSecretKeySpec(algorithm: String, data: String): SecretKey {
return SecretKeySpec( createSecretKey(algorithm,data), algorithm)
}
fun createSecretKeySpec(algorithm: String, data: ByteArray): SecretKey {
return SecretKeySpec( createSecretKey(algorithm,data), algorithm)
}