Skip to content

Commit d523607

Browse files
authored
更新 Crypt.java
1 parent a24b668 commit d523607

File tree

1 file changed

+12
-20
lines changed
  • src/main/java/cc/baka9/catseedlogin/util

1 file changed

+12
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
package cc.baka9.catseedlogin.util;
2-
31
import java.nio.charset.StandardCharsets;
42
import java.security.MessageDigest;
53
import java.security.NoSuchAlgorithmException;
@@ -8,32 +6,26 @@ public class Crypt {
86

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

11-
public static String encrypt(final String name, final String password){
12-
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
9+
public static String encrypt(String name, String password) {
1310
try {
14-
final MessageDigest md = MessageDigest.getInstance("SHA-512");
15-
md.update(text.getBytes(StandardCharsets.UTF_8), 0, text.length());
11+
MessageDigest md = MessageDigest.getInstance("SHA-512");
12+
md.update(("ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password).getBytes(StandardCharsets.UTF_8));
1613
return toHexString(md.digest());
17-
} catch (final NoSuchAlgorithmException e) {
14+
} catch (NoSuchAlgorithmException e) {
1815
return null;
1916
}
2017
}
2118

22-
public static String toHexString(byte... args){
23-
char[] chars = new char[args.length * 2];
24-
for (int i = 0; i < args.length; i++) {
25-
chars[(i * 2)] = CRYPTCHARS[(args[i] >> 4 & 0xF)];
26-
chars[(i * 2 + 1)] = CRYPTCHARS[(args[i] & 0xF)];
19+
private static String toHexString(byte[] bytes) {
20+
char[] chars = new char[bytes.length * 2];
21+
for (int i = 0, j = 0; i < bytes.length; i++) {
22+
chars[j++] = CRYPTCHARS[(bytes[i] >> 4) & 0xF];
23+
chars[j++] = CRYPTCHARS[bytes[i] & 0xF];
2724
}
2825
return new String(chars);
2926
}
3027

31-
public boolean match(final String name, final String password, final String encrypted){
32-
try {
33-
return encrypted.equals(encrypt(name, password));
34-
} catch (final Exception e) {
35-
return false;
36-
}
28+
public static boolean match(String name, String password, String encrypted) {
29+
return encrypted.equals(encrypt(name, password));
3730
}
38-
39-
}
31+
}

0 commit comments

Comments
 (0)