Last active
August 29, 2015 14:23
-
-
Save mamonu/1d0523e42cf571453323 to your computer and use it in GitHub Desktop.
generate a MAC using the ISO9797 Algorithm 3 in Clojure
This file contains hidden or 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
| (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