6 releases (3 breaking)

0.8.2 Jan 9, 2024
0.8.1 Nov 6, 2023
0.8.0 Jan 23, 2023
0.7.0 Dec 28, 2022
0.3.0 Jun 27, 2022

#686 in Cryptography

Download history 65/week @ 2024-08-09 44/week @ 2024-08-16 35/week @ 2024-08-23 64/week @ 2024-08-30 7/week @ 2024-09-06 57/week @ 2024-09-13 146/week @ 2024-09-20 34/week @ 2024-09-27 78/week @ 2024-10-04 48/week @ 2024-10-11 79/week @ 2024-10-18 57/week @ 2024-10-25 86/week @ 2024-11-01 12/week @ 2024-11-08 28/week @ 2024-11-15 4/week @ 2024-11-22

136 downloads per month

Custom license

65KB
1.5K SLoC

Envelopers

Very simple envelope encryption library in Rust using aes-gcm and a KeyProvider trait. KeyProviders can be implemented for AWS KMS, Azure KeyVault, Hashicorp Vault etc but this library just comes with a SimpleKeyProvider that can be used with a local key.

NOTE: This library is very alpha and not yet suitable for production use

Examples

AWS Key Management Service

In order to run the AWS KMS examples you need to ensure the correct environment variables or config options are set to connect to your AWS account.

Follow the AWS getting started docs for help.

Need help?

Head over to our support forum, and we'll get back to you super quick!


lib.rs:

envelope is a very simple, envelope encryption library that can use external key providers such as AWS KMS to encrypt data safely. It uses the concept of data-keys to encrypt messages but these data keys are themselves encrypted by a Key-Encryption-Key (or KEK, sometimes also called Customer Master Key) with the resulting ciphertext stored with the encrypted data (the "wrapped" data-key).

Usage

NOTE: This is Alpha software and should not be used in production

Encrypt a message with a local Key Provider

The SimpleKeyProvider allows envelope encryption to be used with a local key.

use envelopers::{
    Aes128Gcm, // or Aes256Gcm, Aes128GcmSiv, Aes256GcmSiv
    EnvelopeCipher,
    SimpleKeyProvider,
};

#
use hex_literal::hex;
let kek: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f");
let key_provider: SimpleKeyProvider<Aes128Gcm> = SimpleKeyProvider::init(kek);

let cipher: EnvelopeCipher<_> = EnvelopeCipher::init(key_provider);
let er = cipher.encrypt(b"hey there monkey boy").await.unwrap();
#

Encoding a CipherText

#
#
#
#
#
let bytes = er.to_vec().unwrap();
hex::encode(&bytes);

Decrypting a CipherText

use envelopers::{Aes128Gcm, EnvelopeCipher, SimpleKeyProvider, EncryptedRecord};

#
#
#
#
let dec = EncryptedRecord::from_vec(bytes).unwrap();
let pt = cipher.decrypt(&dec).await.unwrap();

assert!(std::str::from_utf8(&pt).unwrap() == "hey there monkey boy");
#

Dependencies

~10–19MB
~250K SLoC