From 5e1236617b52bd63def7bef4a02cda1520bfa38a Mon Sep 17 00:00:00 2001 From: Shuiling <132723284+shulng@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:55:31 -0700 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Crypt.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/baka9/catseedlogin/util/Crypt.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/cc/baka9/catseedlogin/util/Crypt.java b/src/main/java/cc/baka9/catseedlogin/util/Crypt.java index f4f93a5..7c355d0 100644 --- a/src/main/java/cc/baka9/catseedlogin/util/Crypt.java +++ b/src/main/java/cc/baka9/catseedlogin/util/Crypt.java @@ -1,30 +1,33 @@ package cc.baka9.catseedlogin.util; -import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Crypt { - private static final char[] CRYPTCHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + private static final String PREFIX = "ÜÄaeut//&/=I "; + private static final String SUFFIX = "7421€547__+IÄIH§%NK "; + private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); public static String encrypt(String name, String password) { + String text = PREFIX + password + SUFFIX + name + password; try { MessageDigest md = MessageDigest.getInstance("SHA-512"); - md.update(("ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password).getBytes(StandardCharsets.UTF_8)); - return toHexString(md.digest()); + byte[] hashedBytes = md.digest(text.getBytes()); + return toHexString(hashedBytes); } catch (NoSuchAlgorithmException e) { return null; } } private static String toHexString(byte[] bytes) { - char[] chars = new char[bytes.length * 2]; + char[] hexChars = new char[bytes.length * 2]; for (int i = 0, j = 0; i < bytes.length; i++) { - chars[j++] = CRYPTCHARS[(bytes[i] >> 4) & 0xF]; - chars[j++] = CRYPTCHARS[bytes[i] & 0xF]; + int b = bytes[i] & 0xFF; + hexChars[j++] = HEX_CHARS[b >> 4]; + hexChars[j++] = HEX_CHARS[b & 0x0F]; } - return new String(chars); + return new String(hexChars); } public static boolean match(String name, String password, String encrypted) {