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 a24b668 commit d523607
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/main/java/cc/baka9/catseedlogin/util/Crypt.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package cc.baka9.catseedlogin.util;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -8,32 +6,26 @@ public class Crypt {

private static final char[] CRYPTCHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

public static String encrypt(final String name, final String password){
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
public static String encrypt(String name, String password) {
try {
final MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(text.getBytes(StandardCharsets.UTF_8), 0, text.length());
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());
} catch (final NoSuchAlgorithmException e) {
} catch (NoSuchAlgorithmException e) {
return null;
}
}

public static String toHexString(byte... args){
char[] chars = new char[args.length * 2];
for (int i = 0; i < args.length; i++) {
chars[(i * 2)] = CRYPTCHARS[(args[i] >> 4 & 0xF)];
chars[(i * 2 + 1)] = CRYPTCHARS[(args[i] & 0xF)];
private static String toHexString(byte[] bytes) {
char[] chars = 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];
}
return new String(chars);
}

public boolean match(final String name, final String password, final String encrypted){
try {
return encrypted.equals(encrypt(name, password));
} catch (final Exception e) {
return false;
}
public static boolean match(String name, String password, String encrypted) {
return encrypted.equals(encrypt(name, password));
}

}
}

0 comments on commit d523607

Please sign in to comment.