generated from mingliqiye/lib-tem
feat(utils): 添加 BCrypt 加密工具类
- 新增 BCrypt.kt 文件,提供 BCrypt 加密相关方法 - 更新 build.gradle.kts,调整依赖项和版本 - 更新 gradle.properties,升级版本号至 4.1.1 - 更新 HashUtils.kt,使用新的 BCrypt 工具类 - 添加 NOTICE 文件,记录第三方软件的版权声明
This commit is contained in:
parent
fcd528a821
commit
0f5748d55d
25
NOTICE
Normal file
25
NOTICE
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
mingli-utils
|
||||||
|
Copyright 2025 mingliqiye
|
||||||
|
|
||||||
|
This product includes software developed by third parties.
|
||||||
|
The original copyright notices and licenses are reproduced below.
|
||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
https://github.com/jeremyh/jBCrypt (org.mindrot:jbcrypt@0.4)
|
||||||
|
|
||||||
|
Copyright (c) 2006 Damien Miller <djm@mindrot.org>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils
|
* ModuleName mingli-utils
|
||||||
* CurrentFile build.gradle.kts
|
* CurrentFile build.gradle.kts
|
||||||
* LastUpdate 2025-09-17 11:11:57
|
* LastUpdate 2025-09-17 12:08:42
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -65,21 +65,19 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
annotationProcessor("org.jetbrains:annotations:24.0.0")
|
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
implementation("org.slf4j:slf4j-api:2.0.17")
|
||||||
|
|
||||||
|
implementation("com.mingliqiye.utils.jna:WinKernel32Api:1.0.1")
|
||||||
|
// https://github.com/jeremyh/jBCrypt
|
||||||
|
implementation("org.mindrot:jbcrypt:0.4")
|
||||||
|
|
||||||
compileOnly("org.springframework.boot:spring-boot-starter:2.7.14")
|
compileOnly("org.springframework.boot:spring-boot-starter:2.7.14")
|
||||||
compileOnly("com.fasterxml.jackson.core:jackson-databind:2.19.2")
|
compileOnly("com.fasterxml.jackson.core:jackson-databind:2.19.2")
|
||||||
compileOnly("com.google.code.gson:gson:2.13.1")
|
compileOnly("com.google.code.gson:gson:2.13.1")
|
||||||
compileOnly("org.mybatis:mybatis:3.5.19")
|
compileOnly("org.mybatis:mybatis:3.5.19")
|
||||||
compileOnly("com.alibaba.fastjson2:fastjson2:2.0.58")
|
compileOnly("com.alibaba.fastjson2:fastjson2:2.0.58")
|
||||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
|
||||||
implementation("org.bouncycastle:bcprov-jdk18on:1.81")
|
|
||||||
implementation("org.mindrot:jbcrypt:0.4")
|
|
||||||
implementation("org.jetbrains:annotations:24.0.0")
|
|
||||||
compileOnly("net.java.dev.jna:jna:5.17.0")
|
compileOnly("net.java.dev.jna:jna:5.17.0")
|
||||||
implementation("org.slf4j:slf4j-api:2.0.17")
|
|
||||||
implementation("com.mingliqiye.utils.jna:WinKernel32Api:1.0.1")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +94,8 @@ tasks.withType<JavaExec>().configureEach {
|
|||||||
|
|
||||||
tasks.withType<org.gradle.jvm.tasks.Jar> {
|
tasks.withType<org.gradle.jvm.tasks.Jar> {
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
from("LICENSE") { into(".") }
|
from("LICENSE") { into("META-INF") }
|
||||||
|
from("NOTICE") { into("META-INF") }
|
||||||
manifest {
|
manifest {
|
||||||
attributes(
|
attributes(
|
||||||
mapOf(
|
mapOf(
|
||||||
|
|||||||
@ -16,13 +16,13 @@
|
|||||||
# ProjectName mingli-utils
|
# ProjectName mingli-utils
|
||||||
# ModuleName mingli-utils
|
# ModuleName mingli-utils
|
||||||
# CurrentFile gradle.properties
|
# CurrentFile gradle.properties
|
||||||
# LastUpdate 2025-09-17 11:07:06
|
# LastUpdate 2025-09-17 12:10:36
|
||||||
# UpdateUser MingLiPro
|
# UpdateUser MingLiPro
|
||||||
#
|
#
|
||||||
JDKVERSIONS=1.8
|
JDKVERSIONS=1.8
|
||||||
GROUPSID=com.mingliqiye.utils
|
GROUPSID=com.mingliqiye.utils
|
||||||
ARTIFACTID=mingli-utils
|
ARTIFACTID=mingli-utils
|
||||||
VERSIONS=4.1.0
|
VERSIONS=4.1.1
|
||||||
signing.keyId=B22AA93B
|
signing.keyId=B22AA93B
|
||||||
signing.password=
|
signing.password=
|
||||||
signing.secretKeyRingFile=secret.gpg
|
signing.secretKeyRingFile=secret.gpg
|
||||||
|
|||||||
51
src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt
Normal file
51
src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 mingliqiye
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* ProjectName mingli-utils
|
||||||
|
* ModuleName mingli-utils.main
|
||||||
|
* CurrentFile BCrypt.kt
|
||||||
|
* LastUpdate 2025-09-17 11:57:26
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.bcrypt
|
||||||
|
|
||||||
|
import org.mindrot.jbcrypt.BCrypt as JBCrypt
|
||||||
|
|
||||||
|
object BCrypt {
|
||||||
|
fun hashpw(string: String): String {
|
||||||
|
return hashpw(string, gensalt())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hashpw(string: String, salt: String = gensalt()): String {
|
||||||
|
return JBCrypt.hashpw(string, salt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkpw(string: String, bcrypted: String): Boolean {
|
||||||
|
return JBCrypt.checkpw(string, bcrypted)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun gensalt(): String {
|
||||||
|
return JBCrypt.gensalt()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun gensalt(long: Int): String {
|
||||||
|
return JBCrypt.gensalt(long)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun gensalt(long: Int, secureRandom: java.security.SecureRandom): String {
|
||||||
|
return JBCrypt.gensalt(long, secureRandom)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,25 +16,20 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile HashUtils.kt
|
* CurrentFile HashUtils.kt
|
||||||
* LastUpdate 2025-09-15 09:38:04
|
* LastUpdate 2025-09-17 11:57:26
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("HashUtils")
|
@file:JvmName("HashUtils")
|
||||||
|
|
||||||
package com.mingliqiye.utils.hash
|
package com.mingliqiye.utils.hash
|
||||||
|
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
|
||||||
import org.mindrot.jbcrypt.BCrypt
|
import com.mingliqiye.utils.bcrypt.BCrypt
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.NoSuchAlgorithmException
|
import java.security.NoSuchAlgorithmException
|
||||||
import java.security.Security
|
|
||||||
|
|
||||||
private val _addProvider = run {
|
|
||||||
Security.addProvider(BouncyCastleProvider())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算指定文件的哈希值。
|
* 计算指定文件的哈希值。
|
||||||
@ -92,7 +87,7 @@ private fun bytesToHex(bytes: ByteArray): String {
|
|||||||
* @return 加密后的 BCrypt 哈希字符串
|
* @return 加密后的 BCrypt 哈希字符串
|
||||||
*/
|
*/
|
||||||
fun bcrypt(string: String): String {
|
fun bcrypt(string: String): String {
|
||||||
return BCrypt.hashpw(string, BCrypt.gensalt())
|
return BCrypt.hashpw(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user