Last active
September 30, 2023 03:17
-
-
Save joshuakfarrar/91b3f5a4fd54987f365e0c234b64034f to your computer and use it in GitHub Desktop.
implementing Bouncy Castle's argon2 in clojure, from the Leiningen repl
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
(import org.bouncycastle.crypto.generators.Argon2BytesGenerator) | |
(import org.bouncycastle.crypto.params.Argon2Parameters) | |
(import org.bouncycastle.crypto.params.Argon2Parameters$Builder) | |
(import org.bouncycastle.util.encoders.Hex) | |
(defn argon2-hash | |
[version iterations memory parallelism password salt output-length] | |
(let [builder (doto (Argon2Parameters$Builder. Argon2Parameters/ARGON2_i) | |
(.withVersion version) | |
(.withIterations iterations) | |
(.withMemoryPowOfTwo memory) | |
(.withParallelism parallelism) | |
(.withSalt (.getBytes salt "UTF-8"))) | |
params (.build builder) | |
gen (doto (Argon2BytesGenerator.) | |
(.init params)) | |
result (byte-array output-length)] | |
(.generateBytes gen (.toCharArray password) result 0 (alength result)) | |
result)) | |
(-> (argon2-hash Argon2Parameters/ARGON2_VERSION_13 2 16 1 "password" "somesalt" 32) (Hex/toHexString)) | |
; "c1628832147d9720c5bd1cfd61367078729f6dfb6f8fea9ff98158e0d7816ed0" 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment