Skip to content

Instantly share code, notes, and snippets.

@jaydeesimon
Last active June 8, 2018 03:19
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 jaydeesimon/d2e58035edf5eb16bf4c5de8d54cfd74 to your computer and use it in GitHub Desktop.
Save jaydeesimon/d2e58035edf5eb16bf4c5de8d54cfd74 to your computer and use it in GitHub Desktop.
(ns hmac-test.core
(:require [goog.crypt :as crypt]
[goog.crypt.Sha256]
[goog.crypt.Hmac]))
(defn string->bytes [s]
(crypt/stringToUtf8ByteArray s))
(defn bytes->hex [bytes]
(crypt/byteArrayToHex bytes))
(defn hmac-sha256 [secret message]
(let [hasher (goog.crypt.Sha256.)
secret (string->bytes secret)
hmac (goog.crypt.Hmac. hasher secret)]
(bytes->hex (.getHmac hmac message))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment