Skip to content

Instantly share code, notes, and snippets.

@Igvir
Created February 22, 2023 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Igvir/6652eaf6c1e5832e2ae4d3d1d12146a0 to your computer and use it in GitHub Desktop.
Save Igvir/6652eaf6c1e5832e2ae4d3d1d12146a0 to your computer and use it in GitHub Desktop.
DiggestFile
//New file input stream for reading the file content
FileInputStream fis = new FileInputStream(file);
//Create byte array to read data in chunks
byte[] byteArray = new byte[1024];
int bytesCount = 0;
//Read file data and update in message digest
while ((bytesCount = fis.read(byteArray)) != -1) {
digest.update(byteArray, 0, bytesCount);
};
//close the stream; We don't need it now.
fis.close();
//Get the hash's bytes
byte[] bytes = digest.digest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment