|
| 1 | +# SodiumBox |
| 2 | + |
| 3 | +A pure Rust implementation of libsodium's sealed box encryption, compatible with libsodium/sodiumoxide but without any C dependencies. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +The implementation uses modern, well-maintained Rust cryptographic libraries: |
| 10 | + |
| 11 | +- `x25519-dalek` for Curve25519 key exchange |
| 12 | +- `xsalsa20poly1305` for authenticated encryption |
| 13 | +- `blake2` for key derivation |
| 14 | +- `salsa20` for the HSalsa20 function |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +- Generate X25519 keypairs for sealed box operations |
| 19 | +- Seal messages using a recipient's public key |
| 20 | +- Open sealed boxes created by libsodium/sodiumoxide |
| 21 | +- Pure Rust implementation with no C dependencies |
| 22 | +- Comprehensive test vectors based on libsodium's test suite |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +```rust |
| 27 | +use sodiumbox::{generate_keypair, seal, open_sealed_box}; |
| 28 | + |
| 29 | +// Generate a new keypair |
| 30 | +let (public_key, secret_key) = generate_keypair(); |
| 31 | + |
| 32 | +// Create a message to encrypt |
| 33 | +let message = b"This is a secret message"; |
| 34 | + |
| 35 | +// Seal the message for the recipient |
| 36 | +let sealed_box = seal(message, &public_key); |
| 37 | + |
| 38 | +// Open a sealed box |
| 39 | +let result = open_sealed_box(&sealed_box, &public_key, &secret_key); |
| 40 | +match result { |
| 41 | + Ok(plaintext) => println!("Decrypted message: {:?}", plaintext), |
| 42 | + Err(_) => println!("Failed to decrypt"), |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +## License |
| 47 | + |
| 48 | +This crate is licensed under either of: |
| 49 | + |
| 50 | +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 51 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 52 | + |
| 53 | +at your option. |
0 commit comments