Enabling Client-Side Encryption in Cloud Storage


Client-side encryption is an effective way to protect sensitive data stored in the cloud. With client-side encryption, data is encrypted before it leaves the application and is only decrypted after it is downloaded, so it remains protected while at rest in the cloud. Even if another party, or the storage provider itself, gains access to the data, it remains encrypted and unusable without the proper credentials.

Every storage component in Cloud Storage supports client-side encryption through the EncryptionPassword and EncryptionAlgorithm properties.

Contents

Encrypting and Decrypting Files

When the EncryptionPassword property is set, the component automatically encrypts data before uploading it and decrypts data after downloading it. No other changes to the upload or download code are required.

As an example, consider the following code using the Dropbox component, which uploads and downloads a file without encryption:

Dropbox dropbox = new Dropbox(); dropbox.Authorization = "Bearer ACCESS_TOKEN"; string dropboxPath = "/My Folder/sensitiveData.zip"; // Upload the file. dropbox.LocalFile = "../MySensitiveData.zip"; dropbox.UploadFile(dropboxPath); // Download the file. dropbox.LocalFile = "../MySensitiveData2.zip"; dropbox.DownloadFile(dropboxPath);

To enable client-side encryption, set the EncryptionPassword property before calling UploadFile or DownloadFile. The same password must be used to download the file as was used to upload it.

Dropbox dropbox = new Dropbox(); dropbox.Authorization = "Bearer ACCESS_TOKEN"; string dropboxPath = "/My Folder/sensitiveData.zip"; // Set the encryption password to enable client-side encryption and decryption. dropbox.EncryptionPassword = "encryption password"; // Upload the file. The data is encrypted before it is sent. dropbox.LocalFile = "../MySensitiveData.zip"; dropbox.UploadFile(dropboxPath); // Download the file. The data is decrypted after it is received. dropbox.LocalFile = "../MySensitiveData2.zip"; dropbox.DownloadFile(dropboxPath);

If EncryptionPassword is not set when an encrypted file is downloaded, the encrypted data is downloaded as-is.

Client-side encryption also works with uploads and downloads that use streams, and with resumable uploads and downloads. When resuming an encrypted download, LocalFile must have been set for the initial download attempt; refer to the component documentation for details.

Choosing an Algorithm

The EncryptionAlgorithm property specifies which encryption algorithm is used. The default is AES with a 256-bit key, so this property only needs to be set to use a different algorithm. The maximum key size for the selected algorithm is always used.

// AES is the default, so this line is optional. dropbox.EncryptionAlgorithm = DropboxEncryptionAlgorithms.eaAES;

Other supported algorithms include Blowfish, CAST, DES, IDEA, RC2, RC4, TEA, Triple DES, Twofish, Rijndael, ChaCha, and XSalsa20. AES is recommended unless a different algorithm is required for compatibility with another system. The same algorithm must be used to download a file as was used to upload it.

Key Derivation and FIPS Compliance

By default, the component derives the encryption key and initialization vector (IV) from EncryptionPassword using the PBKDF1 key derivation function. The EncryptionPasswordKDF configuration setting can be set to 1 to use PBKDF2 instead.

PBKDF1 is not FIPS compliant, so when operating in FIPS mode, EncryptionPasswordKDF must be set to 1, or the component will return an error. For more information about FIPS mode, please see our FIPS 140-2 Compliance in SSL/TLS, SSH, SMIME and Cloud Components article.

// Derive the key and IV from the password using PBKDF2. dropbox.Config("EncryptionPasswordKDF=1"); dropbox.EncryptionPassword = "encryption password";

Since the key derivation function determines the key and IV, a file must be downloaded with the same EncryptionPasswordKDF value that was used to upload it.

Specifying the Key and IV Directly

Instead of deriving the key and IV from a password, the key and IV can be specified directly using the EncryptionKey and EncryptionIV configuration settings. Both settings accept hex-encoded values. This may be necessary when the data must be encrypted or decrypted by another application that generates keys differently.

// Specify the hex-encoded key and IV directly instead of using a password. dropbox.Config("EncryptionKey=HEX_ENCODED_KEY"); dropbox.Config("EncryptionIV=HEX_ENCODED_IV"); dropbox.LocalFile = "../MySensitiveData.zip"; dropbox.UploadFile(dropboxPath);

Interoperability

The encryption performed by the Cloud Storage components is compatible with the EzCrypt component in IPWorks Encrypt. A file that was uploaded with client-side encryption, and then downloaded without setting EncryptionPassword, can be decrypted with EzCrypt using the same algorithm and password (or key and IV). This allows encrypted files to be decrypted outside of the application that uploaded them, such as in a separate recovery or auditing tool.

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.