README: enhance sha1 example
This commit is contained in:
parent
5b88953d05
commit
fd61bb1a1c
1 changed files with 16 additions and 7 deletions
23
README.md
23
README.md
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue