Safe Haskell | None |
---|---|
Language | Haskell2010 |
Internals of crypto_box
.
Synopsis
- type SecretKey a = SizedByteArray CRYPTO_BOX_SECRETKEYBYTES a
- toSecretKey :: ByteArrayAccess bytes => bytes -> Maybe (SecretKey bytes)
- type PublicKey a = SizedByteArray CRYPTO_BOX_PUBLICKEYBYTES a
- toPublicKey :: ByteArrayAccess bytes => bytes -> Maybe (PublicKey bytes)
- keypair :: IO (PublicKey ByteString, SecretKey ScrubbedBytes)
- type Nonce a = SizedByteArray CRYPTO_BOX_NONCEBYTES a
- toNonce :: ByteArrayAccess ba => ba -> Maybe (Nonce ba)
- create :: (ByteArrayAccess pkBytes, ByteArrayAccess skBytes, ByteArrayAccess nonce, ByteArrayAccess pt, ByteArray ct) => PublicKey pkBytes -> SecretKey skBytes -> Nonce nonce -> pt -> IO ct
- open :: (ByteArrayAccess skBytes, ByteArrayAccess pkBytes, ByteArrayAccess nonce, ByteArray pt, ByteArrayAccess ct) => SecretKey skBytes -> PublicKey pkBytes -> Nonce nonce -> ct -> IO (Maybe pt)
Documentation
type SecretKey a = SizedByteArray CRYPTO_BOX_SECRETKEYBYTES a Source #
Secret key that can be used for Box.
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
.
toSecretKey :: ByteArrayAccess bytes => bytes -> Maybe (SecretKey bytes) Source #
Convert bytes to a secret key.
type PublicKey a = SizedByteArray CRYPTO_BOX_PUBLICKEYBYTES a Source #
Public key that can be used for Box.
This type is parametrised by the actual data type that contains
bytes. This can be, for example, a ByteString
.
toPublicKey :: ByteArrayAccess bytes => bytes -> Maybe (PublicKey bytes) Source #
Convert bytes to a public key.
keypair :: IO (PublicKey ByteString, SecretKey ScrubbedBytes) Source #
Generate a new SecretKey
together with its PublicKey
.
Note: this function is not thread-safe (since the underlying
C function is not thread-safe both in Sodium and in NaCl)!
Either make sure there are no concurrent calls or see
Crypto.Init
in
crypto-sodium
to learn how to make this function thread-safe.
type Nonce a = SizedByteArray CRYPTO_BOX_NONCEBYTES a Source #
Nonce that can be used for Box.
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 Box.
:: (ByteArrayAccess pkBytes, ByteArrayAccess skBytes, ByteArrayAccess nonce, ByteArrayAccess pt, ByteArray ct) | |
=> PublicKey pkBytes | Receiver’s public key |
-> SecretKey skBytes | Sender’s secret key |
-> Nonce nonce | Nonce |
-> pt | Plaintext message |
-> IO ct |
Encrypt a message.
:: (ByteArrayAccess skBytes, ByteArrayAccess pkBytes, ByteArrayAccess nonce, ByteArray pt, ByteArrayAccess ct) | |
=> SecretKey skBytes | Receiver’s secret key |
-> PublicKey pkBytes | Sender’s public key |
-> Nonce nonce | Nonce |
-> ct | Cyphertext |
-> IO (Maybe pt) |
Decrypt a message.