pax_global_header00006660000000000000000000000064137567707250014535gustar00rootroot0000000000000052 comment=44dea07b802c34c1d8a7cefeb0c004216d285ac4 crypto-random-1.2.1/000077500000000000000000000000001375677072500143345ustar00rootroot00000000000000crypto-random-1.2.1/.gitignore000066400000000000000000000001101375677072500163140ustar00rootroot00000000000000pom.xml *jar /lib/ /classes/ /target/ .lein-deps-sum .lein-repl-history crypto-random-1.2.1/README.md000066400000000000000000000015351375677072500156170ustar00rootroot00000000000000# crypto-random A small Clojure library for generating cryptographically secure random bytes and strings. ## Installation Add the following dependency to your `project.clj` file: [crypto-random "1.2.1"] ## Functions ### `(crypto.random/bytes size)` Returns a random byte array of the specified size. ### `(crypto.random/base64 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. ### `(crypto.random/url-part size)` Return a random string suitable for being inserted into URLs. The size denotes the number of bytes to generate. ## License Copyright © 2020 James Reeves Distributed under the Eclipse Public License, the same as Clojure. crypto-random-1.2.1/project.clj000066400000000000000000000005421375677072500164750ustar00rootroot00000000000000(defproject crypto-random "1.2.1" :description "Library for generating secure random bytes and strings" :url "https://github.com/weavejester/crypto-random" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.7.0"] [commons-codec "1.15"]]) crypto-random-1.2.1/src/000077500000000000000000000000001375677072500151235ustar00rootroot00000000000000crypto-random-1.2.1/src/crypto/000077500000000000000000000000001375677072500164435ustar00rootroot00000000000000crypto-random-1.2.1/src/crypto/random.clj000066400000000000000000000020601375677072500204130ustar00rootroot00000000000000(ns crypto.random "Cryptographically secure random numbers and strings." (:refer-clojure :exclude [bytes]) (:require [clojure.string :as string]) (:import java.security.SecureRandom [org.apache.commons.codec.binary Base64 Base32 Hex])) (defn bytes "Returns a random byte array of the specified size." [size] (let [seed (byte-array size)] (.nextBytes (SecureRandom.) seed) seed)) (defn base64 "Return a random base64 string of the specified size in bytes." [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] (String. (Hex/encodeHex ^bytes (bytes size)))) (defn url-part "Return a random string suitable for being inserted into URLs. The size denotes the number of bytes to generate." [size] (-> (base64 size) (string/replace "+" "-") (string/replace "/" "_") (string/replace "=" "")))