1 unstable release
new 0.1.0 | May 15, 2025 |
---|
#768 in Cryptography
17KB
200 lines
SodiumBox
A pure Rust implementation of libsodium's sealed box encryption, compatible with libsodium/sodiumoxide but without any C dependencies.
Overview
SodiumBox provides a standalone implementation of the sealed box functionality from libsodium (NaCl) using only pure Rust cryptographic libraries. It is designed to be a drop-in replacement for sodiumoxide's sealed box functionality.
The implementation uses modern, well-maintained Rust cryptographic libraries:
x25519-dalek
for Curve25519 key exchangexsalsa20poly1305
for authenticated encryptionblake2
for key derivationsalsa20
for the HSalsa20 function
Features
- Generate X25519 keypairs for sealed box operations
- Seal messages using a recipient's public key
- Open sealed boxes created by libsodium/sodiumoxide
- Pure Rust implementation with no C dependencies
- Comprehensive test vectors based on libsodium's test suite
Usage
use sodiumbox::{generate_keypair, seal, open_sealed_box};
// Generate a new keypair
let (public_key, secret_key) = generate_keypair();
// Create a message to encrypt
let message = b"This is a secret message";
// Seal the message for the recipient
let sealed_box = seal(message, &public_key);
// Open a sealed box
let result = open_sealed_box(&sealed_box, &public_key, &secret_key);
match result {
Ok(plaintext) => println!("Decrypted message: {:?}", plaintext),
Err(_) => println!("Failed to decrypt"),
}
License
This crate is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~2.4–3.5MB
~75K SLoC