README: enhance sha1 example

This commit is contained in:
Michiel Borkent 2020-03-21 11:48:06 +01:00
parent 5b88953d05
commit fd61bb1a1c

View file

@ -1040,17 +1040,26 @@ clojure.core/ffirst
### SHA hash string and print in hex ### SHA hash string and print in hex
`sha.clj`: `sha1.clj`:
``` clojure ``` clojure
(def hashed (.digest (.getInstance java.security.MessageDigest "SHA-1") #!/usr/bin/env bb
(.getBytes "babashka")))
(doseq [b hashed] (defn sha1
(print (format "%02X" b))) [s]
(let [hashed (.digest (.getInstance java.security.MessageDigest "SHA-1")
(.getBytes s))
sw (java.io.StringWriter.)]
(binding [*out* sw]
(doseq [byte hashed]
(print (format "%02X" byte))))
(str sw)))
(sha1 (first *command-line-args*))
``` ```
``` shell ``` shell
bb sha.clj sha1.clj
0AB318BE3A646EEB1E592781CBFE4AE59701EDDF "0AB318BE3A646EEB1E592781CBFE4AE59701EDDF"
``` ```
## Thanks ## Thanks