Created
April 24, 2010 21:27
-
-
Save jblomo/377964 to your computer and use it in GitHub Desktop.
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
(defn sha1 | |
"Compute the SHA-1 of a File's contents and return the hex string" | |
[file] | |
(with-open [f (FileInputStream. file)] | |
(let [buffer (byte-array 1024) | |
md (MessageDigest/getInstance "SHA-1") ] | |
(loop [nread (.read f buffer)] | |
(if (pos? nread) | |
(do (.update md buffer 0 nread) | |
(recur (.read f buffer))) | |
(format "%040x" (BigInteger. 1 (.digest md)) 16)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment