Created
May 7, 2012 12:20
-
-
Save FredericJacobs/2627474 to your computer and use it in GitHub Desktop.
Hashing
This file contains 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
private byte[] generateHash() { | |
MessageDigest messageDigestInstance = null; | |
byte[] hash = null; | |
try { | |
messageDigestInstance = MessageDigest.getInstance("SHA-1"); | |
DigestInputStream dis = new DigestInputStream(new DataInputStream( | |
new FileInputStream(this)), messageDigestInstance); | |
while (dis.read() != -1) | |
; | |
dis.close(); | |
hash = messageDigestInstance.digest(); | |
} catch (FileNotFoundException e) { | |
System.err | |
.println("File not found while generating hash for DataFile."); | |
} catch (NoSuchAlgorithmException e) { | |
System.err | |
.println("Algorithm does not exist while generating hash for DataFile."); | |
} catch (IOException e) { | |
System.err | |
.println("I/O Exception while generating hash for DataFile."); | |
} | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment