All Projects → lk-geimfari → secrets.clj

lk-geimfari / secrets.clj

Licence: MIT License
A library designed to generate cryptographically strong random numbers.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to secrets.clj

RNG
A simple state-of-the-art C++ random number generator
Stars: ✭ 19 (-70.31%)
Mutual labels:  random, prng, rng
Uniuri
Go package uniuri generates random strings good for use in URIs to identify unique objects.
Stars: ✭ 336 (+425%)
Mutual labels:  uuid, random, secure
macos-receiver
A MacOS TabBar (StatusBar) application that securely receives one-time passwords (OTPs) that you tapped in Raivo for iOS.
Stars: ✭ 44 (-31.25%)
Mutual labels:  password, secure
secrets
Useful to get input on noecho, secrets, passwords, token, hints
Stars: ✭ 13 (-79.69%)
Mutual labels:  secrets, password
rocRAND
RAND library for HIP programming language
Stars: ✭ 68 (+6.25%)
Mutual labels:  random, rng
bookshelf-secure-password
A Bookshelf.js plugin for handling secure passwords
Stars: ✭ 24 (-62.5%)
Mutual labels:  password, secure
MlkPwgen
Secure random password generator for .NET and PowerShell
Stars: ✭ 57 (-10.94%)
Mutual labels:  random, password
prvhash
PRVHASH - Pseudo-Random-Value Hash. Hash functions, PRNG with unlimited period, randomness extractor. (Codename Gradilac/Градилак)
Stars: ✭ 194 (+203.13%)
Mutual labels:  random, prng
2ami
Your easy 2FA companion that keep the secrets secret.
Stars: ✭ 24 (-62.5%)
Mutual labels:  secrets, secure
ios-application
A native, lightweight and secure one-time-password (OTP) client built for iOS; Raivo OTP!
Stars: ✭ 581 (+807.81%)
Mutual labels:  password, secure
ruuid
A fast uuid generator in Python using Rust
Stars: ✭ 19 (-70.31%)
Mutual labels:  uuid, random
javascript-strong-password-generator
JavaScript Strong Password Generator: based on Jeff Atwood's Post "Password Rules Are Bullshit".
Stars: ✭ 21 (-67.19%)
Mutual labels:  random, password
randomgen
Numpy-compatible bit generators and add some random variate distributions missing from NumPy.
Stars: ✭ 82 (+28.13%)
Mutual labels:  prng, rng
lrng
Linux Random Number Generator
Stars: ✭ 57 (-10.94%)
Mutual labels:  random, rng
jsrand
A seeded pseudo-random number generator for JavaScript.
Stars: ✭ 19 (-70.31%)
Mutual labels:  random, prng
order-id
Unique order id generator
Stars: ✭ 46 (-28.12%)
Mutual labels:  random, timestamp
evildork
Evildork targeting your fiancee👁️
Stars: ✭ 46 (-28.12%)
Mutual labels:  secrets, password
Kirby3 Autoid
Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
Stars: ✭ 58 (-9.37%)
Mutual labels:  uuid, random
Nanoid
A tiny, secure, URL-friendly, unique string ID generator for Rust
Stars: ✭ 188 (+193.75%)
Mutual labels:  uuid, random
colossal-squuid
Library for generating sequential UUIDs, or SQUUIDs
Stars: ✭ 52 (-18.75%)
Mutual labels:  uuid, timestamp

test codecov Clojars Version Cljdoc Badge

The secrets.clj is a library designed to generate cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.

The secrets.clj is a port of the secrets module from Python's standard library for Clojure.

Installation

Leiningen/Boot:

Add the following dependency to your project.clj file:

[likid_geimfari/secrets "1.1.1"]

Documentation

You can find the complete documentation on the cljdoc.

Usage examples

user=> (secrets.core/token-hex 32)
"2aa5430064918acf140bb423678cef7353f7055597bc61305414c5371106ebef"

user=> (secrets.core/token-urlsafe 32)
"kfbGVrB6jz6hyOl_2rX9UIHgiop2-rM_jo2XEK7oTj0"

user=> (secrets.core/token-bytes 16)
#object["[B" 0x3b2454e9 "[B@3b2454e9"]

user=> (secrets.core/randbelow 100)
71

user=> (secrets.core/choice [8 16 32 64 128])
8

user=> (secrets.core/choices [8 16 32 64 128] 2)
(128 16)

user=> (secrets.tools/uuid4)
"84e9c5c0-ceb4-4aab-9a58-668f59b9a9e5"

user=> (secrets.tools/unix-timestamp)
1601927558

See «Recipes and best practices» for more usage examples.

Recipes and best practices

This section shows recipes and best practices for using secrets to manage a basic level of security.

Generate an eight-character alphanumeric password:

(ns example.security
  (:use [clojure.string :only [join]]
    [secrets.core]
    [secrets.constants :only [ascii-letters digits]]))

(defn generate-password [n]
  (join "" (secrets.core/choices (str ascii-letters digits)) n))
example.security=> (generate-password 8)
"7gHY2N4s"

Note: Applications should not store passwords in a recoverable format, whether plain text or encrypted. They should be salted and hashed using a cryptographically-strong one-way (irreversible) hash function.

Generate an XKCD-style passphrase:

(ns example.security
  (:use [secrets.core]
        [clojure.string :only [join lower-case split-lines]))

(def words
  (-> (slurp "/usr/share/dict/words")
      (split-lines)))

(defn generate-passphrase [n]
  (-> (join " " (secrets.core/choices words n))
      (lower-case)))
example.security=> (generate-passphrase 5)
"uniaxally intercarrier straddleback basihyoid unhusk"

Generate a hard-to-guess temporary URL containing a security token suitable for password recovery applications:

(ns example.security
  (:use [secrets.core :only [token-urlsafe]]))

(defn generate-password-recovery-url [n]
  (str "https://mydomain.com/reset=" (token-urlsafe n)))
example.security=> (generate-password-recovery-url 32)
"https://mydomain.com/reset=3kOJuScK1mHyxXWnuMBAUQaIEdsBUluQBR-3Zlvv8XQ"

License

MIT License. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].