1
- package cc .baka9 .catseedlogin .util ;
2
-
3
1
import java .nio .charset .StandardCharsets ;
4
2
import java .security .MessageDigest ;
5
3
import java .security .NoSuchAlgorithmException ;
@@ -8,32 +6,26 @@ public class Crypt {
8
6
9
7
private static final char [] CRYPTCHARS = {'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
10
8
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 ) {
13
10
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 ));
16
13
return toHexString (md .digest ());
17
- } catch (final NoSuchAlgorithmException e ) {
14
+ } catch (NoSuchAlgorithmException e ) {
18
15
return null ;
19
16
}
20
17
}
21
18
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 ];
27
24
}
28
25
return new String (chars );
29
26
}
30
27
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 ));
37
30
}
38
-
39
- }
31
+ }
0 commit comments