Module dryoc::crypto_secretbox [−][src]
Authenticated encryption functions
Implements libsodium’s secret-key authenticated crypto boxes.
For details, refer to libsodium docs.
Classic API example
use dryoc::rng::randombytes_buf; use dryoc::crypto_secretbox::{crypto_secretbox_keygen, crypto_secretbox_easy, crypto_secretbox_open_easy}; use dryoc::constants::CRYPTO_SECRETBOX_NONCEBYTES; use dryoc::nonce::Nonce; use dryoc::traits::*; let key = crypto_secretbox_keygen(); let nonce = randombytes_buf(CRYPTO_SECRETBOX_NONCEBYTES); let nonce = Nonce::gen(); let message = "I Love Doge!"; // Encrypt let ciphertext = crypto_secretbox_easy(message.as_bytes(), &nonce, &key).unwrap(); // Decrypt let decrypted = crypto_secretbox_open_easy(&ciphertext, &nonce, &key).unwrap(); assert_eq!(decrypted, message.as_bytes());
Functions
crypto_secretbox_detached | Detached version of crypto_secretbox_easy |
crypto_secretbox_easy | Encrypts |
crypto_secretbox_easy_inplace | Encrypts |
crypto_secretbox_keygen | Generates a random key using randombytes_buf |
crypto_secretbox_open_detached | Detached version of crypto_secretbox_open_easy |
crypto_secretbox_open_easy | Decrypts |
crypto_secretbox_open_easy_inplace | Decrypts |