Crypto Module

Small crypto module that can do HMACs and generate random strings to use as keys, as well as create a 'cryptobox'; i.e. a AES256+HMACSHA256 box with compressed plaintext contents so that they can be easily stored in cookies.

Types

Type Description

SecretboxDecryptionError

SecretboxEncryptionError

Functions and values

Function or value Description

BlockSize

Full Usage: BlockSize

Returns: uint16

# bits in block

Returns: uint16

HMACAlgorithm

Full Usage: HMACAlgorithm

Returns: string

The default hmac algorithm

Returns: string

HMACLength

Full Usage: HMACLength

Returns: uint16

The length of the HMAC value in number of bytes

Returns: uint16

IVLength

Full Usage: IVLength

Returns: uint16

# bytes in IV 16 bytes for 128 bit blocks

Returns: uint16

KeyLength

Full Usage: KeyLength

Returns: uint16

# bytes in key

Returns: uint16

KeySize

Full Usage: KeySize

Returns: uint16

# bits in key

Returns: uint16

cryptRandom

Full Usage: cryptRandom

Returns: RandomNumberGenerator

the global crypto-random pool for uniform and therefore cryptographically secure random values

Returns: RandomNumberGenerator

equalsConstantTime bits bobs

Full Usage: equalsConstantTime bits bobs

Parameters:
    bits : byte[]
    bobs : byte[]

Returns: bool

Compare two byte arrays in constant time, bounded by the length of the longest byte array.

bits : byte[]
bobs : byte[]
Returns: bool

generateIV ivLength

Full Usage: generateIV ivLength

Parameters:
    ivLength : uint16

Returns: byte[]
ivLength : uint16
Returns: byte[]

generateKey keyLength

Full Usage: generateKey keyLength

Parameters:
    keyLength : uint16

Returns: byte[]

Generates a string key from the available characters with the given key size.

keyLength : uint16
Returns: byte[]

generateKeys ()

Full Usage: generateKeys ()

Parameters:
    () : unit

Returns: byte[] * byte[]

key: 32 bytes for 256 bit key Returns a new key and a new iv as two byte arrays as a tuple.

() : unit
Returns: byte[] * byte[]

generateStdIV ()

Full Usage: generateStdIV ()

Parameters:
    () : unit

Returns: byte[]
() : unit
Returns: byte[]

generateStdKey ()

Full Usage: generateStdKey ()

Parameters:
    () : unit

Returns: byte[]
() : unit
Returns: byte[]

hmacAtOffset key offset count data

Full Usage: hmacAtOffset key offset count data

Parameters:
    key : byte[]
    offset : int
    count : int
    data : byte[]

Returns: byte[]

Calculate the HMAC of the passed data given a private key

key : byte[]
offset : int
count : int
data : byte[]
Returns: byte[]

hmacOfBytes key data

Full Usage: hmacOfBytes key data

Parameters:
    key : byte[]
    data : byte[]

Returns: byte[]
key : byte[]
data : byte[]
Returns: byte[]

hmacOfText key data

Full Usage: hmacOfText key data

Parameters:
    key : byte[]
    data : string seq

Returns: byte[]

Calculate the HMAC value given the key and a seq of string-data which will be concatenated in its order and hmac-ed.

key : byte[]
data : string seq
Returns: byte[]

randomize bytes

Full Usage: randomize bytes

Parameters:
    bytes : byte[]

Returns: byte[]

Fills the passed array with random bytes

bytes : byte[]
Returns: byte[]

secretbox key msg

Full Usage: secretbox key msg

Parameters:
    key : byte[]
    msg : byte[]

Returns: Choice<byte[], SecretboxEncryptionError>
key : byte[]
msg : byte[]
Returns: Choice<byte[], SecretboxEncryptionError>

secretboxOfText key msg

Full Usage: secretboxOfText key msg

Parameters:
    key : byte[]
    msg : string

Returns: Choice<byte[], SecretboxEncryptionError>
key : byte[]
msg : string
Returns: Choice<byte[], SecretboxEncryptionError>

secretboxOpen key cipherText

Full Usage: secretboxOpen key cipherText

Parameters:
    key : byte[]
    cipherText : byte[]

Returns: Choice<byte[], SecretboxDecryptionError>
key : byte[]
cipherText : byte[]
Returns: Choice<byte[], SecretboxDecryptionError>

secretboxOpenAsString keyText cipherText

Full Usage: secretboxOpenAsString keyText cipherText

Parameters:
    keyText : byte[]
    cipherText : byte[]

Returns: Choice<string, SecretboxDecryptionError>
keyText : byte[]
cipherText : byte[]
Returns: Choice<string, SecretboxDecryptionError>