generated from mingliqiye/lib-tem
add
All checks were successful
Gitea Actions Build / Build (push) Successful in 5m36s
All checks were successful
Gitea Actions Build / Build (push) Successful in 5m36s
This commit is contained in:
parent
56080634c7
commit
d991b4077b
@ -144,6 +144,9 @@ tasks.withType<org.gradle.jvm.tasks.Jar> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = uri("https://maven.aliyun.com/repository/public/")
|
||||||
|
}
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -21,7 +21,7 @@
|
|||||||
#
|
#
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@ -47,6 +47,16 @@ public class OsPath implements Path {
|
|||||||
return new OsPath(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
|
@Override
|
||||||
public @NotNull FileSystem getFileSystem() {
|
public @NotNull FileSystem getFileSystem() {
|
||||||
return path.getFileSystem();
|
return path.getFileSystem();
|
||||||
|
|||||||
@ -24,9 +24,12 @@
|
|||||||
|
|
||||||
package com.mingliqiye.utils
|
package com.mingliqiye.utils
|
||||||
|
|
||||||
|
import com.mingliqiye.utils.path.OsPath
|
||||||
import com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
import com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
||||||
|
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
AutoConfiguration.printBanner()
|
AutoConfiguration.printBanner()
|
||||||
|
val path = OsPath.getCwd()
|
||||||
|
println(path.toAbsolutePath())
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/main/kotlin/com/mingliqiye/utils/security/AesUtils.kt
Normal file
35
src/main/kotlin/com/mingliqiye/utils/security/AesUtils.kt
Normal 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))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
33
src/main/kotlin/com/mingliqiye/utils/security/SecureUtils.kt
Normal file
33
src/main/kotlin/com/mingliqiye/utils/security/SecureUtils.kt
Normal 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)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user