Skip to content

Instantly share code, notes, and snippets.

@Porama6400
Created January 12, 2018 03:06
Show Gist options
  • Select an option

  • Save Porama6400/7285399ab42c8d735202a2ac7b612f0c to your computer and use it in GitHub Desktop.

Select an option

Save Porama6400/7285399ab42c8d735202a2ac7b612f0c to your computer and use it in GitHub Desktop.
A method to checksum a file
public static String checksum(File file) throws IOException, NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buff = new byte[bis.available()];
bis.read(buff, 0, buff.length);
byte[] hash = digest.digest(buff);
return new BASE64Encoder().encode(hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment