|
1 | 1 | package cc.baka9.catseedlogin.util;
|
2 | 2 |
|
3 |
| -import java.nio.charset.StandardCharsets; |
4 | 3 | import java.security.MessageDigest;
|
5 | 4 | import java.security.NoSuchAlgorithmException;
|
6 | 5 |
|
7 | 6 | public class Crypt {
|
8 | 7 |
|
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(); |
10 | 11 |
|
11 | 12 | public static String encrypt(String name, String password) {
|
| 13 | + String text = PREFIX + password + SUFFIX + name + password; |
12 | 14 | try {
|
13 | 15 | 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); |
16 | 18 | } catch (NoSuchAlgorithmException e) {
|
17 | 19 | return null;
|
18 | 20 | }
|
19 | 21 | }
|
20 | 22 |
|
21 | 23 | private static String toHexString(byte[] bytes) {
|
22 |
| - char[] chars = new char[bytes.length * 2]; |
| 24 | + char[] hexChars = new char[bytes.length * 2]; |
23 | 25 | 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]; |
26 | 29 | }
|
27 |
| - return new String(chars); |
| 30 | + return new String(hexChars); |
28 | 31 | }
|
29 | 32 |
|
30 | 33 | public static boolean match(String name, String password, String encrypted) {
|
|
0 commit comments