Skip to content

Instantly share code, notes, and snippets.

@jblomo
Created April 24, 2010 21:27
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 jblomo/377964 to your computer and use it in GitHub Desktop.
Save jblomo/377964 to your computer and use it in GitHub Desktop.
(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