Use the correct hashing algorithm

This commit is contained in:
Johannes Frohnmeyer 2021-12-31 11:28:19 +01:00
parent 567a91f7d0
commit 2bf5eea248
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 5 additions and 4 deletions

View File

@ -17,7 +17,6 @@ import java.io.IOException;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
@Mixin(ServerPropertiesHandler.class)
public class ServerPropertiesHandlerMixin {
@ -33,9 +32,11 @@ public class ServerPropertiesHandlerMixin {
resourcePackSha1 = "";
if (Cfg.hashResources) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(Files.readAllBytes(DynRes.resFile));
resourcePackSha1 = Base64.getEncoder().encodeToString(hash);
StringBuilder result = new StringBuilder();
for (byte b : MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(DynRes.resFile))) {
result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
}
resourcePackSha1 = result.toString();
DynRes.LOGGER.info("Set hash to " + resourcePackSha1);
} catch (IOException | NoSuchAlgorithmException e) {
DynRes.LOGGER.error("Failed to get hash, continuing with empty", e);