NaCl-0.0.1.0: Easy-and-safe-to-use library for cryptography
Safe HaskellNone
LanguageHaskell2010

Crypto.Secretbox

Synopsis

Documentation

type Key a = OfLength CRYPTO_SECRETBOX_KEYBYTES a Source #

Encryption key that can be used for Secretbox.

This type is parametrised by the actual data type that contains bytes. This can be, for example, a ByteString, but, since this is a secret key, it is better to use ScrubbedBytes.

toKey :: ByteArrayAccess ba => ba -> Maybe (Key ba) Source #

Make a Key from an arbitrary byte array.

This function returns Just if and only if the byte array has the right length to be used as a key with a Secretbox.

type Nonce a = OfLength CRYPTO_SECRETBOX_NONCEBYTES a Source #

Nonce that can be used for Secretbox.

This type is parametrised by the actual data type that contains bytes. This can be, for example, a ByteString.

toNonce :: ByteArrayAccess ba => ba -> Maybe (Nonce ba) Source #

Make a Nonce from an arbitrary byte array.

This function returns Just if and only if the byte array has the right length to be used as a nonce with a Secretbox.

create Source #

Arguments

:: (ByteArrayAccess key, ByteArrayAccess nonce, ByteArrayAccess pt, ByteArray ct) 
=> Key key

Secret key

-> Nonce nonce

Nonce

-> pt

Plaintext message

-> ct 

Encrypt a message.

Note: This function is similar to the C++ API of NaCl. That is, unlike crypto_secretbox from the C API of NaCl, it does not require any special padding.

open Source #

Arguments

:: (ByteArrayAccess key, ByteArrayAccess nonce, ByteArray pt, ByteArrayAccess ct) 
=> Key key

Secret key

-> Nonce nonce

Nonce

-> ct

Cyphertext

-> Maybe pt 

Decrypt a message.

Note: This function is similar to the C++ API of NaCl. That is, unlike crypto_secretbox_open from the C API of NaCl, it does not require any special padding.