Skip to content

Commit

Permalink
更新 Crypt.java
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Jun 12, 2024
1 parent f10833d commit 5e12366
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/cc/baka9/catseedlogin/util/Crypt.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 5e12366

Please sign in to comment.