Skip to content

Instantly share code, notes, and snippets.

@dsp
Created July 6, 2010 12:20
Show Gist options
  • Save dsp/465314 to your computer and use it in GitHub Desktop.
Save dsp/465314 to your computer and use it in GitHub Desktop.
(ns
#^{:doc "Utilities"}
gh.util
(:import java.security.MessageDigest))
(defn digest
"Calculates a digest with the given algorithm"
([str] (digest str "SHA1"))
([str dig]
(apply vector (.digest (MessageDigest/getInstance dig) (.getBytes str)))))
(defn vec-to-str
"Converts a vector to a string representation"
[vec]
(apply str (map #(format "%02x" (bit-and 0xff %)) vec)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment