Created
July 23, 2018 07:56
-
-
Save toomasr/9c37e5312b453e0a99d5c3fcf283719b to your computer and use it in GitHub Desktop.
Packing the same bytes twice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.math.BigInteger; | |
import java.nio.file.Files; | |
import java.security.MessageDigest; | |
import org.zeroturnaround.zip.ZipUtil; | |
public class ZipUtilPackMd5 { | |
public static void main(String[] args) throws Exception { | |
String fileName = "target/classes/ZipUtilPackMd5.class"; | |
File file = new File(fileName); | |
if (!file.exists()) | |
throw new RuntimeException(fileName + " does not exist"); | |
byte[] bytes = Files.readAllBytes(file.toPath()); | |
System.out.println("Input file " + md5(bytes)); | |
byte[] zippedBytes = ZipUtil.packEntry(file); | |
System.out.println(md5(zippedBytes)); | |
zippedBytes = ZipUtil.packEntry(file); | |
System.out.println(md5(zippedBytes)); | |
} | |
private static String md5(byte[] bytes) throws Exception { | |
MessageDigest m = MessageDigest.getInstance("MD5"); | |
m.update(bytes, 0, bytes.length); | |
return "md5: " + new BigInteger(1, m.digest()).toString(16); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment