This article was first published on Medium, take a look here. Enjoy!
Envelope encryption is a technique that combines symmetric and asymmetric encryption to improve performance.
A key value suitable for use with a symmetric encryption algorithm such as AES is chosen randomly, then it is used to encrypt plaintext. This plaintext is referred to as the document, and the key is called the document encryption key (DEK).
The DEK itself is then asymmetrically encrypted with a user’s public key. The resulting encrypted DEK can be stored with the data or elsewhere.
To recover the document the encrypted DEK is first decrypted using the user’s private key.
Once the DEK is recovered, it can be used to decrypt the underlying document data.
The disadvantage of public key cryptography is that every user that a document will be shared with must be known before the document is encrypted to them. If data is encrypted to multiple users, it must be separately encrypted with each user’s public key. To revoke user access, we must possess and change the underlying data (and all its copies).
To address these disadvantages, combine transform encryption with public key cryptography when encrypting to multiple users. Transform encryption encrypts the DEK to an arbitrary entity called a group and later transforms the encrypted DEK from the group to the single user.
A transform service uses a transform key to perform the “Encrypted DEK — group” to “Encrypted DEK — user” mapping, the DEK is not decrypted in this process, it is a ciphertext-to-ciphertext transform.
After the encrypted DEK is transformed from group to user, the user’s private key can be used to decrypt the encrypted DEK. The DEK is then used to decrypt the document.
Symmetric encryption uses one key for both encryption and decryption. It is fast and straightforward. The main drawback is that users must find a way to share the symmetric key securely.
Asymmetric encryption uses two keys that are mathematically related (generally called a key pair). Plaintext or document data is encrypted with the public key and decrypted using the corresponding private key.
Public key encryption is another name for asymmetric encryption. It is called public key cryptography because the encryption key can be shared publicly, while the decryption key must be kept private.