Last active
May 29, 2018 12:54
-
-
Save masanobuimai/c674244ad1b5230e4a007c6f00e69339 to your computer and use it in GitHub Desktop.
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
package com.example; | |
import javax.xml.bind.DatatypeConverter; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.InputStream; | |
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
public class MD5Sum { | |
public static void main(String[] args) throws Exception { | |
MessageDigest md5 = MessageDigest.getInstance("MD5"); | |
// String name = "out/production/md5sum/com/example/MD5Sum.class"; | |
String name = "md5sum.iml"; | |
try (InputStream is = new FileInputStream(new File(name))) { | |
byte[] buffer = new byte[1024]; | |
int read = 0; | |
while ((read = is.read(buffer)) > 0) { | |
md5.update(buffer); | |
} | |
} | |
byte[] sum = md5.digest(); | |
System.out.println("1:" + DatatypeConverter.printHexBinary(sum)); | |
System.out.println("2:" + new BigInteger(1, sum).toString(16)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment