nonce-1.0.4: Generate cryptographic nonces.

Safe Haskell | None
Language | Haskell2010

Crypto.Nonce

Description

Usage of this module is very simple. Here is a sample GHCi run:

    *Crypto.Nonce> g <- new
    *Crypto.Nonce> nonce128 g
    "c\164\252\162f\207\245\ESC`\180p\DC4\234\223QP"
    *Crypto.Nonce> nonce128 g
    "\203C\190\138aI\158\194\146\&7\208\&7\ETX0\f\229"
    *Crypto.Nonce> nonce128url g
    "3RP-iEFT-6NrpCMsxigondMC"
    *Crypto.Nonce> nonce128url g
    "MVZH3Gi5zSKXJY-_qdtznxla"
    *Crypto.Nonce> nonce128url g
    "3f3cVNfuZT62-uGco1CBThci"
    *Crypto.Nonce> nonce128urlT g
    "iGMJyrRkw2QMp09SRy59s4Jx"
    *Crypto.Nonce> nonce128urlT g
    "WsHs0KwYiex3tsqQZ8b0119_"
    *Crypto.Nonce> nonce128urlT g
    "JWkLSX7qSFGu1Q3PHuExwurF"

The functions that generate nonces are not pure on purpose, since that makes it a lot harder to reuse the same nonce.

Synopsis

- data Generator
- new :: MonadIO m => m Generator
- nonce128 :: MonadIO m => Generator -> m ByteString
- nonce128url :: MonadIO m => Generator -> m ByteString
- nonce128urlT :: MonadIO m => Generator -> m Text

# Documentation

data Generator #

An encapsulated nonce generator.

Instances

Show Generator # |
Methods showsPrec :: Int -> Generator -> ShowS # show :: Generator -> String # showList :: [Generator] -> ShowS #

new :: MonadIO m => m Generator #

Create a new nonce generator using the system entropy.

nonce128 :: MonadIO m => Generator -> m ByteString #

Generate a 128 bit nonce as a `ByteString` of 16 bytes. Each byte may have any value from `0` to `255`.

nonce128url :: MonadIO m => Generator -> m ByteString #

Generate a 128 bit nonce as a `ByteString` of 24 bytes. Each byte is either a letter (upper or lowercase), a digit, a dash (`-`) or an underscore (`_`), which is the set of characters from the base64url encoding. In order to avoid any issues with padding, the generated nonce actually has 144 bits.

nonce128urlT :: MonadIO m => Generator -> m Text #

Same as `nonce128url`, but returns its result as `Text` instead.