Skip to content

Commit

Permalink
feat: 修改加密算法从MD5改为SHA-256以提高安全性
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed May 28, 2024
1 parent 00b3245 commit 6e25a3a
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/main/java/cc/baka9/catseedlogin/util/CommunicationAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@

public class CommunicationAuth {

public static String encryption(String... args) {
String paramString = String.join("", args);
private static MessageDigest messageDigest;

static {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(paramString.getBytes());
byte[] arrayOfByte = messageDigest.digest();
StringBuilder stringBuilder = new StringBuilder();
for (byte value : arrayOfByte) {
int unsignedByte = value & 0xff;
if (unsignedByte < 16) stringBuilder.append("0");
stringBuilder.append(Integer.toHexString(unsignedByte));
}
return stringBuilder.toString().toLowerCase();
messageDigest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
return null;
// 适当地处理异常
e.printStackTrace();
}
}

public static String encryption(String... args) {
String paramString = String.join("", args);
byte[] arrayOfByte = messageDigest.digest(paramString.getBytes());
StringBuilder stringBuilder = new StringBuilder();
for (byte value : arrayOfByte) {
int unsignedByte = value & 0xff;
if (unsignedByte < 16) stringBuilder.append("0");
stringBuilder.append(Integer.toHexString(unsignedByte));
}
return stringBuilder.toString().toLowerCase();
}

}
}

0 comments on commit 6e25a3a

Please sign in to comment.