Skip to content

Instantly share code, notes, and snippets.

@mamonu
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save mamonu/1d0523e42cf571453323 to your computer and use it in GitHub Desktop.

Select an option

Save mamonu/1d0523e42cf571453323 to your computer and use it in GitHub Desktop.
generate a MAC using the ISO9797 Algorithm 3 in Clojure
(defn mac2 [key message]
(let [engine (org.bouncycastle.crypto.engines.DESEngine.)
mac (org.bouncycastle.crypto.macs.ISO9797Alg3Mac. engine)
bytes (byte-array (.getMacSize mac))
key (->bytes key)
msg (->bytes E-IFD)]
(prn key (count key))
(.init mac (org.bouncycastle.crypto.params.DESedeParameters. key))
(.update mac msg 0 (count msg))
(.doFinal mac bytes 0)
(->hex-string bytes)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment