Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Created September 25, 2010 09:10
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 yayitswei/596646 to your computer and use it in GitHub Desktop.
Save yayitswei/596646 to your computer and use it in GitHub Desktop.
(ns oauth.digest
(:import (javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)))
(defn hmac
"Calculate HMAC signature for given data."
[^String key ^String data]
(let [hmac-sha1 "HmacSHA1"
signing-key (SecretKeySpec. (.getBytes key) hmac-sha1)
mac (doto (Mac/getInstance hmac-sha1) (.init signing-key))]
(String. (org.apache.commons.codec.binary.Base64/encodeBase64
(.doFinal mac (.getBytes data)))
"UTF-8")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment