10 releases (4 breaking)

Uses new Rust 2021

0.5.1 Sep 9, 2022
0.5.0 Sep 5, 2022
0.4.1 Aug 26, 2022
0.3.0 Jun 27, 2022
0.1.3 May 19, 2022

#606 in Cryptography

Download history 76/week @ 2022-06-04 68/week @ 2022-06-11 265/week @ 2022-06-18 398/week @ 2022-06-25 392/week @ 2022-07-02 383/week @ 2022-07-09 389/week @ 2022-07-16 402/week @ 2022-07-23 454/week @ 2022-07-30 434/week @ 2022-08-06 393/week @ 2022-08-13 370/week @ 2022-08-20 382/week @ 2022-08-27 447/week @ 2022-09-03 455/week @ 2022-09-10 307/week @ 2022-09-17

1,663 downloads per month
Used in cipherstash-client

GPL-3.0 license

49KB
1K 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::{EnvelopeCipher, SimpleKeyProvider};

# use tokio::runtime::Runtime;
# let rt = Runtime::new().unwrap();
# rt.block_on(async {
#
use hex_literal::hex;
let kek: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f");
let key_provider = SimpleKeyProvider::init(kek);

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

Encoding a CipherText

# use envelopers::{EnvelopeCipher, SimpleKeyProvider};
#
# use tokio::runtime::Runtime;
# let rt = Runtime::new().unwrap();
# rt.block_on(async {
#
# use hex_literal::hex;
# let kek: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f");
# let key_provider = SimpleKeyProvider::init(kek);
#
# let cipher: EnvelopeCipher<SimpleKeyProvider> = EnvelopeCipher::init(
#   key_provider,
# );
#
# let er = cipher.encrypt(b"hey there monkey boy").await.unwrap();
#
let bytes = er.to_vec().unwrap();
hex::encode(&bytes);
# });

Decrypting a CipherText

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

#
# use tokio::runtime::Runtime;
# let rt = Runtime::new().unwrap();
# rt.block_on(async {
#
# use hex_literal::hex;
# let kek: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f");
# let key_provider = SimpleKeyProvider::init(kek);
#
# let cipher: EnvelopeCipher<SimpleKeyProvider> = EnvelopeCipher::init(
#    key_provider,
# );
# let er = cipher.encrypt(b"hey there monkey boy").await.unwrap();
# let bytes = er.to_vec().unwrap();
# hex::encode(&bytes);
#
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

~2.5–8MB
~156K SLoC