[#790] Add java.security.SecureRandom
This commit is contained in:
parent
970ab1bee9
commit
f3630d2fb3
2 changed files with 13 additions and 0 deletions
|
|
@ -189,6 +189,7 @@
|
|||
java.nio.file.attribute.PosixFilePermissions])
|
||||
java.security.MessageDigest
|
||||
java.security.DigestInputStream
|
||||
java.security.SecureRandom
|
||||
~@(when features/java-time?
|
||||
`[java.time.format.DateTimeFormatter
|
||||
java.time.Clock
|
||||
|
|
|
|||
|
|
@ -587,6 +587,18 @@ true"))
|
|||
(.force view)
|
||||
true")))
|
||||
|
||||
(deftest secure-random-test
|
||||
(let [prog '(do (import 'java.security.SecureRandom 'java.util.Base64)
|
||||
|
||||
(let [random (SecureRandom.)
|
||||
base64 (.withoutPadding (Base64/getUrlEncoder))]
|
||||
(defn generate-token []
|
||||
(let [buffer (byte-array 32)]
|
||||
(.nextBytes random buffer)
|
||||
(.encodeToString base64 buffer))))
|
||||
(generate-token))]
|
||||
(is (string? (bb nil (str prog))))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
Loading…
Reference in a new issue