sel-0.0.1.0: Cryptography for the casual user
Copyright(C) Hécate Moonlight 2022
LicenseBSD-3-Clause
MaintainerThe Haskell Cryptography Group
PortabilityGHC only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Sel.PublicKey.Seal

Description

 
Synopsis

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

newtype PublicKey Source #

A public key of size cryptoBoxPublicKeyBytes.

Since: 0.0.1.0

Constructors

PublicKey (ForeignPtr CUChar) 

Instances

Instances details
Show PublicKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Eq PublicKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Ord PublicKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Display PublicKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

newtype SecretKey Source #

A secret key of size cryptoBoxSecretKeyBytes.

Since: 0.0.1.0

Constructors

SecretKey (ForeignPtr CUChar) 

Instances

Instances details
Show SecretKey Source #
show secretKey == "[REDACTED]"

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Eq SecretKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Ord SecretKey Source #

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

Display SecretKey Source #
display secretKey == "[REDACTED]"

Since: 0.0.1.0

Instance details

Defined in Sel.PublicKey.Cipher

newKeyPair :: IO (PublicKey, SecretKey) Source #

Generate a new random secret key.

May throw KeyPairGenerationException if the generation fails.

Since: 0.0.1.0

Operations

seal Source #

Arguments

:: 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

open Source #

Arguments

:: 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