Skip to content

Commit 6e25a3a

Browse files
committed
feat: 修改加密算法从MD5改为SHA-256以提高安全性
1 parent 00b3245 commit 6e25a3a

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/main/java/cc/baka9/catseedlogin/util/CommunicationAuth.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55

66
public class CommunicationAuth {
77

8-
public static String encryption(String... args) {
9-
String paramString = String.join("", args);
8+
private static MessageDigest messageDigest;
9+
10+
static {
1011
try {
11-
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
12-
messageDigest.update(paramString.getBytes());
13-
byte[] arrayOfByte = messageDigest.digest();
14-
StringBuilder stringBuilder = new StringBuilder();
15-
for (byte value : arrayOfByte) {
16-
int unsignedByte = value & 0xff;
17-
if (unsignedByte < 16) stringBuilder.append("0");
18-
stringBuilder.append(Integer.toHexString(unsignedByte));
19-
}
20-
return stringBuilder.toString().toLowerCase();
12+
messageDigest = MessageDigest.getInstance("SHA-256");
2113
} catch (NoSuchAlgorithmException e) {
22-
return null;
14+
// 适当地处理异常
15+
e.printStackTrace();
16+
}
17+
}
18+
19+
public static String encryption(String... args) {
20+
String paramString = String.join("", args);
21+
byte[] arrayOfByte = messageDigest.digest(paramString.getBytes());
22+
StringBuilder stringBuilder = new StringBuilder();
23+
for (byte value : arrayOfByte) {
24+
int unsignedByte = value & 0xff;
25+
if (unsignedByte < 16) stringBuilder.append("0");
26+
stringBuilder.append(Integer.toHexString(unsignedByte));
2327
}
28+
return stringBuilder.toString().toLowerCase();
2429
}
2530

26-
}
31+
}

0 commit comments

Comments
 (0)