| Crates.io | sifredb |
| lib.rs | sifredb |
| version | 0.1.1 |
| created_at | 2025-11-13 06:39:57.904333+00 |
| updated_at | 2025-11-14 00:41:07.139033+00 |
| description | Field-level encryption library with envelope encryption and blind indexes |
| homepage | |
| repository | https://github.com/Tuntii/sifredb |
| max_upload_size | |
| id | 1930505 |
| size | 106,178 |
A Rust library for field-level encryption with envelope encryption and blind indexes.
Add this to your Cargo.toml:
[dependencies]
sifredb = "0.1"
use sifredb::prelude::*;
// Create encryption context
let context = EncryptionContext::new("users", "email")
.with_tenant("tenant_123");
// Use deterministic vault for encryption
let key = b"32-byte-key-here-must-be-32-byte";
let vault = DeterministicVault::new(key);
// Encrypt
let plaintext = b"alice@example.com";
let ciphertext = vault.encrypt(plaintext, &context)?;
// Decrypt
let decrypted = vault.decrypt(&ciphertext, &context)?;
assert_eq!(plaintext, &decrypted[..]);
Deterministic encryption produces the same ciphertext for the same plaintext, enabling equality queries:
use sifredb::prelude::*;
let vault = DeterministicVault::new(key);
let context = EncryptionContext::new("users", "ssn");
let cipher1 = vault.encrypt(b"123-45-6789", &context)?;
let cipher2 = vault.encrypt(b"123-45-6789", &context)?;
// Same plaintext = same ciphertext (enables database equality queries)
assert_eq!(cipher1, cipher2);
The encryption context binds encrypted data to specific use cases:
use sifredb::prelude::*;
let context = EncryptionContext::new("users", "email")
.with_tenant("tenant_abc") // Multi-tenant isolation
.with_version(1); // Key version for rotation
// Context is cryptographically bound to the ciphertext
// Decryption with wrong context will fail
Different tenants use different encryption keys automatically:
use sifredb::prelude::*;
let vault = DeterministicVault::new(key);
// Tenant A
let context_a = EncryptionContext::new("users", "email")
.with_tenant("tenant_a");
let cipher_a = vault.encrypt(b"alice@tenant-a.com", &context_a)?;
// Tenant B (different encryption due to different context)
let context_b = EncryptionContext::new("users", "email")
.with_tenant("tenant_b");
let cipher_b = vault.encrypt(b"alice@tenant-b.com", &context_b)?;
// Ciphertexts are different even if email addresses were the same
SifreDB uses AES-SIV (Synthetic IV) for deterministic encryption:
For probabilistic encryption, combine with external key providers for full envelope encryption.
See the repository for more examples:
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.