Module dryoc::crypto_box [−][src]
Authenticated public-key cryptography functions
Implements libsodium’s public-key authenticated crypto boxes.
For details, refer to libsodium docs.
Classic API example
use dryoc::prelude::*; use dryoc::rng::randombytes_buf; // Not included in prelude use dryoc::constants::CRYPTO_BOX_NONCEBYTES; // Not included in prelude use std::convert::TryInto; // Create a random sender keypair let keypair_sender = crypto_box_keypair(); // Create a random recipient keypair let keypair_recipient = crypto_box_keypair(); // Generate a random nonce let nonce: Nonce = randombytes_buf(CRYPTO_BOX_NONCEBYTES).try_into().unwrap(); let message = "hello".as_bytes(); // Encrypt message let ciphertext = crypto_box_easy( message, &nonce, &keypair_recipient.public_key.0, &keypair_sender.secret_key.0, ) .unwrap(); // Decrypt message let decrypted_message = crypto_box_open_easy( &ciphertext, &nonce, &keypair_sender.public_key.0, &keypair_recipient.secret_key.0, ) .unwrap(); assert_eq!(message, decrypted_message);
Functions
crypto_box_beforenm | Computes a shared secret for the given |
crypto_box_detached | Detached variant of |
crypto_box_detached_afternm | Precalculation variant of |
crypto_box_detached_afternm_inplace | In-place variant of |
crypto_box_detached_inplace | In-place variant of crypto_box_detached |
crypto_box_easy | Encrypts |
crypto_box_easy_inplace | Encrypts |
crypto_box_keypair | Generates a public/secret key pair using OS provided data using rand_core::OsRng |
crypto_box_open_detached | Detached variant of |
crypto_box_open_detached_afternm | Precalculation variant of crypto_box_open_easy |
crypto_box_open_detached_afternm_inplace | In-place variant of crypto_box_open_detached_afternm |
crypto_box_open_detached_inplace | In-place variant of [‘crypto_box_open_detached’] |
crypto_box_open_easy | Decrypts |
crypto_box_open_easy_inplace | Decrypts |
crypto_box_seed_keypair | Deterministically derives a keypair from |