Skip to content

Instantly share code, notes, and snippets.

@gbzarelli
Created November 22, 2018 17:49
Show Gist options
  • Save gbzarelli/1aff184b67111c7165deda71d74947cb to your computer and use it in GitHub Desktop.
Save gbzarelli/1aff184b67111c7165deda71d74947cb to your computer and use it in GitHub Desktop.
How to get SHA-1 from File
// 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