Created
November 22, 2018 17:49
-
-
Save gbzarelli/1aff184b67111c7165deda71d74947cb to your computer and use it in GitHub Desktop.
How to get SHA-1 from File
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
// new FileInputStream(file); | |
public static String getSHA1(InputStream input) throws | |
IOException, NoSuchAlgorithmException { | |
MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); | |
byte[] buffer = new byte[8192]; | |
int len = input.read(buffer); | |
while (len != -1) { | |
sha1.update(buffer, 0, len); | |
len = input.read(buffer); | |
} | |
return new HexBinaryAdapter().marshal(sha1.digest()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment