Last active
October 19, 2018 18:50
-
-
Save bpringe/9e4602b8cfd5f768d63b06601723d4f2 to your computer and use it in GitHub Desktop.
Calcuate HMAC signature. Substitute `algorithm` for other types. This worked for me for validating Facebook webhook payloads.
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
;; Make sure you import javax.crypto.Mac and javax.crypto.spec.SecretKeySpec | |
(defn get-signature | |
[message secret] | |
(let [algorithm "HmacSHA1" | |
signing-key (SecretKeySpec. (.getBytes secret) algorithm) | |
mac (doto | |
(Mac/getInstance algorithm) | |
(.init signing-key)) | |
bytes->hex-str #(apply str (for [b %] (format "%02x" b)))] | |
(->> (.getBytes message) | |
(.doFinal mac) | |
bytes->hex-str))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment