fix: 修正了数据库命名错误的问题.

由于 MessageDigest 不适用于多线程环境, 导致用于创建数据库名称的数据会不断累加, 最终出现 botToken 无法对应数据库的问题.
This commit is contained in:
LamGC 2022-01-16 21:12:48 +08:00
parent 37f0d4e6b8
commit 19c601817c
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 3 additions and 4 deletions

View File

@ -8,7 +8,8 @@ final class ByteUtils {
public static String bytesToHexString(byte[] bytes) {
StringBuilder builder = new StringBuilder();
for (byte aByte : bytes) {
builder.append(Integer.toHexString(aByte));
String hexBit = Integer.toHexString(aByte & 0xFF);
builder.append(hexBit.length() == 1 ? "0" + hexBit : hexBit);
}
return builder.toString();
}

View File

@ -8,10 +8,8 @@ import java.nio.charset.StandardCharsets
import java.security.MessageDigest
internal object BotDBMaker {
private val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
fun getBotMaker(botAccount: BotAccount): DBContext {
val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
val digestBytes = digest.digest(botAccount.token.toByteArray(StandardCharsets.UTF_8))
val dbPath = AppPaths.DATA_DB.path + "${digestBytes.toHaxString()}.db"
val db = DBMaker.fileDB(dbPath)