MB
The X-Loop-Signature is a base-64, HMAC hash of body payload using the Webhook Secret provided by Loop.
Size: a a a
MB
MB
MP
IG
(defn- factory
"Builds a function to compute the HMAC of a payload, given a secret-key.
`hmac-type` is the algorithm to use for the HMAC."
[^String hmac-type input-transformer key-transformer output-transformer]
(fn [secret-string ^String raw-input]
(let [secret ^"[B" (key-transformer secret-string)
input ^"[B" (input-transformer raw-input)
key (SecretKeySpec. secret hmac-type)]
(-> (doto (Mac/getInstance hmac-type) (.init key))
(.doFinal input)
(output-transformer)))))
IG
(def sha256 (factory "HmacSHA256"
string->bytes
string->bytes
b->b64))
IG
(sha256 secret-key payload)
Г
^"[B"?MP
MB
MB
(-> (json/generate-string sample)
(mac/hash {:key "d5044d4220937b57" :alg :hmac})
(codecs/bytes->b64)
A
(ns hmac
(:import (javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)))
(defn toHexString [bytes]
(apply str (map #(format "%02x" %) bytes)))
(defn hmac [^String key ^String string]
(let [mac (Mac/getInstance "HmacSHA256")
secretKey (SecretKeySpec. (.getBytes key) (.getAlgorithm mac))]
(-> (doto mac
(.init secretKey)
(.update (.getBytes string)))
.doFinal
toHexString)))
A
MB
A
A
MB
(-> (js/write-str body :escape-slash true)
(mac/hash {:key "d5044d4220937b57" :alg :hmac})
(codecs/bytes->hex)
);; => "b5ada318e1e774c11133240fc7ab05174eca91cae81372e0121205cf08a28262"
A
MB
ST