Sealed boxes allow a sender to encrypt a message for a recipient using only the recipient's public key. This provides anonymity because the sender uses an ephemeral key pair that is erased immediately after encryption, meaning the sender cannot decrypt the message later and the recipient cannot verify the sender's identity from the ciphertext alone.
Key Characteristics:
- Anonymity: The sender's identity cannot be correlated with the message without additional data.
- One-way: The sender cannot decrypt the message once it is sent.
- Integrity: The recipient can verify the integrity of the message.
- Compatibility: Uses standard
crypto_box key pairs (X25519 and XSalsa20-Poly1305).
/* Recipient creates a long-term key pair */
unsigned char recipient_pk[crypto_box_PUBLICKEYBYTES];
unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(recipient_pk, recipient_sk);
/* Anonymous sender encrypts a message using an ephemeral key pair
* and the recipient's public key */
unsigned char ciphertext[CIPHERTEXT_LEN];
crypto_box_seal(ciphertext, MESSAGE, MESSAGE_LEN, recipient_pk);
/* Recipient decrypts the ciphertext */
unsigned char decrypted[MESSAGE_LEN];
if (crypto_box_seal_open(decrypted, ciphertext, CIPHERTEXT_LEN,
recipient_pk, recipient_sk) != 0) {
/* message corrupted or not intended for this recipient */
}