Skip to content

Commit 5e12366

Browse files
authored
更新 Crypt.java
1 parent f10833d commit 5e12366

File tree

1 file changed

+11
-8
lines changed
  • src/main/java/cc/baka9/catseedlogin/util

1 file changed

+11
-8
lines changed

src/main/java/cc/baka9/catseedlogin/util/Crypt.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
package cc.baka9.catseedlogin.util;
22

3-
import java.nio.charset.StandardCharsets;
43
import java.security.MessageDigest;
54
import java.security.NoSuchAlgorithmException;
65

76
public class Crypt {
87

9-
private static final char[] CRYPTCHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
8+
private static final String PREFIX = "ÜÄaeut//&/=I ";
9+
private static final String SUFFIX = "7421€547__+IÄIH§%NK ";
10+
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
1011

1112
public static String encrypt(String name, String password) {
13+
String text = PREFIX + password + SUFFIX + name + password;
1214
try {
1315
MessageDigest md = MessageDigest.getInstance("SHA-512");
14-
md.update(("ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password).getBytes(StandardCharsets.UTF_8));
15-
return toHexString(md.digest());
16+
byte[] hashedBytes = md.digest(text.getBytes());
17+
return toHexString(hashedBytes);
1618
} catch (NoSuchAlgorithmException e) {
1719
return null;
1820
}
1921
}
2022

2123
private static String toHexString(byte[] bytes) {
22-
char[] chars = new char[bytes.length * 2];
24+
char[] hexChars = new char[bytes.length * 2];
2325
for (int i = 0, j = 0; i < bytes.length; i++) {
24-
chars[j++] = CRYPTCHARS[(bytes[i] >> 4) & 0xF];
25-
chars[j++] = CRYPTCHARS[bytes[i] & 0xF];
26+
int b = bytes[i] & 0xFF;
27+
hexChars[j++] = HEX_CHARS[b >> 4];
28+
hexChars[j++] = HEX_CHARS[b & 0x0F];
2629
}
27-
return new String(chars);
30+
return new String(hexChars);
2831
}
2932

3033
public static boolean match(String name, String password, String encrypted) {

0 commit comments

Comments
 (0)