Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added base32 encoding

  • Loading branch information...
commit 4255c2e3f3ed1bda0ed0900b8e294d19f470b263 1 parent 462b7ce
@pelle pelle authored
Showing with 11 additions and 2 deletions.
  1. +4 −0 README.md
  2. +1 −1  project.clj
  3. +6 −1 src/crypto/random.clj
View
4 README.md
@@ -19,6 +19,10 @@ Returns a random byte array of the specified size.
Return a random base64 string of the specified size in bytes.
+### `(crypto.random/base32 size)`
+
+Return a random base32 string of the specified size in bytes.
+
### `(crypto.random/hex size)`
Return a random hex string of the specified size in bytes.
View
2  project.clj
@@ -2,4 +2,4 @@
:description "Library for generating secure random bytes and strings"
:url "https://github.com/weavejester/crypto-random"
:dependencies [[org.clojure/clojure "1.2.1"]
- [commons-codec "1.4"]])
+ [commons-codec "1.6"]])
View
7 src/crypto/random.clj
@@ -3,7 +3,7 @@
(:refer-clojure :exclude [bytes])
(:require [clojure.string :as string])
(:import java.security.SecureRandom
- [org.apache.commons.codec.binary Base64 Hex]))
+ [org.apache.commons.codec.binary Base64 Base32 Hex]))
(defn bytes
"Returns a random byte array of the specified size."
@@ -17,6 +17,11 @@
[size]
(String. (Base64/encodeBase64 (bytes size))))
+(defn base32
+ "Return a random base32 string of the specified size in bytes."
+ [size]
+ (.encodeAsString (Base32.) (bytes size)))
+
(defn hex
"Return a random hex string of the specified size in bytes."
[size]
Please sign in to comment.
Something went wrong with that request. Please try again.