Copyright | (C) Hécate Moonlight 2022 |
---|---|
License | BSD-3-Clause |
Maintainer | The Haskell Cryptography Group |
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- newtype PublicKey = PublicKey (ForeignPtr CUChar)
- newtype SecretKey = SecretKey (ForeignPtr CUChar)
- newKeyPair :: IO (PublicKey, SecretKey)
- seal :: StrictByteString -> PublicKey -> IO CipherText
- open :: CipherText -> PublicKey -> SecretKey -> Maybe StrictByteString
- data KeyPairGenerationException
- data EncryptionError
Introduction
Ephemeral authenticated encryption allows to anonymously send message to a recipient given their public key.
Only the recipient can decrypt these messages using their own secret key. While the recipient can verify the integrity of the message, they cannot verify the identity of the sender.
A message is encrypted using an ephemeral key pair, with the secret key being erased right after the encryption process.
Without knowing the secret key used for a given message, the sender cannot decrypt their own message later. Furthermore, without additional data, a message cannot be correlated with the identity of its sender.
Usage
import qualified Sel.PublicKey.Seal as Seal main = do -- We get the recipient their pair of keys: (recipientPublicKey, recipientSecretKey) <- newKeyPair encryptedMessage <- Seal.encrypt "hello hello" recipientPublicKey let result = Seal.open encryptedMessage recipientPublicKey recipientSecretKey print result -- "Just \"hello hello\""
Keys
A public key of size cryptoBoxPublicKeyBytes
.
Since: 0.0.1.0
Instances
Show PublicKey Source # | Since: 0.0.1.0 |
Eq PublicKey Source # | Since: 0.0.1.0 |
Ord PublicKey Source # | Since: 0.0.1.0 |
Defined in Sel.PublicKey.Cipher | |
Display PublicKey Source # | Since: 0.0.1.0 |
Defined in Sel.PublicKey.Cipher displayBuilder :: PublicKey -> Builder # displayList :: [PublicKey] -> Builder # displayPrec :: Int -> PublicKey -> Builder # |
A secret key of size cryptoBoxSecretKeyBytes
.
Since: 0.0.1.0
Instances
Show SecretKey Source # | show secretKey == "[REDACTED]" Since: 0.0.1.0 |
Eq SecretKey Source # | Since: 0.0.1.0 |
Ord SecretKey Source # | Since: 0.0.1.0 |
Defined in Sel.PublicKey.Cipher | |
Display SecretKey Source # | display secretKey == "[REDACTED]" Since: 0.0.1.0 |
Defined in Sel.PublicKey.Cipher displayBuilder :: SecretKey -> Builder # displayList :: [SecretKey] -> Builder # displayPrec :: Int -> SecretKey -> Builder # |
newKeyPair :: IO (PublicKey, SecretKey) Source #
Generate a new random secret key.
May throw KeyPairGenerationException
if the generation fails.
Since: 0.0.1.0
Operations
:: StrictByteString | Message to encrypt |
-> PublicKey | Public key of the recipient |
-> IO CipherText |
Encrypt a message with the recipient's public key. A key pair for the sender is generated, and the public key of that pair is attached to the cipher text. The secret key of the sender's pair is automatically destroyed.
Since: 0.0.1.0
:: CipherText | Cipher to decrypt |
-> PublicKey | Public key of the recipient |
-> SecretKey | Secret key of the recipient |
-> Maybe StrictByteString |
Open a sealed message from an unknown sender. You need your public and secret keys.
Since: 0.0.1.0
Errors
data KeyPairGenerationException Source #
Exception thrown upon error during the generation of
the key pair by newKeyPair
.
Since: 0.0.1.0
Instances
data EncryptionError Source #
Exception thrown upon error during the encryption
of the message by encrypt
.
Since: 0.0.1.0
Instances
Exception EncryptionError Source # | |
Defined in Sel.PublicKey.Cipher | |
Show EncryptionError Source # | |
Defined in Sel.PublicKey.Cipher showsPrec :: Int -> EncryptionError -> ShowS # show :: EncryptionError -> String # showList :: [EncryptionError] -> ShowS # | |
Eq EncryptionError Source # | |
Defined in Sel.PublicKey.Cipher (==) :: EncryptionError -> EncryptionError -> Bool # (/=) :: EncryptionError -> EncryptionError -> Bool # | |
Ord EncryptionError Source # | |
Defined in Sel.PublicKey.Cipher compare :: EncryptionError -> EncryptionError -> Ordering # (<) :: EncryptionError -> EncryptionError -> Bool # (<=) :: EncryptionError -> EncryptionError -> Bool # (>) :: EncryptionError -> EncryptionError -> Bool # (>=) :: EncryptionError -> EncryptionError -> Bool # max :: EncryptionError -> EncryptionError -> EncryptionError # min :: EncryptionError -> EncryptionError -> EncryptionError # |