Always Encrypted cryptography - SQL Server (2024)

  • Article

Applies to: Always Encrypted cryptography - SQL Server (1) SQL Server Always Encrypted cryptography - SQL Server (2) Azure SQL Database Always Encrypted cryptography - SQL Server (3) Azure SQL Managed Instance

This document describes encryption algorithms and mechanisms to derive cryptographic material used in the Always Encrypted feature in SQL Server and Azure SQL Database.

Keys, key stores, and key encryption algorithms

Always Encrypted uses two types of keys: Column master keys and column encryption keys.

A column master key (CMK) is a key encrypting key (for example, a key that is used to encrypt other keys) that is always in a client's control, and is stored in an external key store. An Always Encrypted-enabled client driver interacts with the key store via a CMK store provider, which can be either part of the driver library (a Microsoft/system provider) or part of the client application (a custom provider). Client driver libraries currently include Microsoft key store providers for Windows Certificate Store and hardware security modules (HSMs). For the current list of providers, see CREATE COLUMN MASTER KEY (Transact-SQL). An application developer can supply a custom provider for an arbitrary store.

A column encryption key (CEK), is a content encryption key (for example, a key that is used to protect data) that is protected by a CMK.

All Microsoft CMK store providers encrypt CEKs by using RSA with Optimal Asymmetric Encryption Padding (RSA-OAEP). The key store provider that supports Microsoft Cryptography API: Next Generation (CNG) in .NET Framework (SqlColumnEncryptionCngProvider Class) uses the default parameters specified by RFC 8017 in Section A.2.1. Those default parameters are using a hash function of SHA-1 and a mask generation function of MGF1 with SHA-1. All other key store providers use SHA-256.

Always Encrypted internally uses FIPS 140-2 validated cryptographic modules.

Data Encryption Algorithm

Always Encrypted uses the AEAD_AES_256_CBC_HMAC_SHA_256 algorithm to encrypt data in the database.

AEAD_AES_256_CBC_HMAC_SHA_256 is derived from the specification draft at https://tools.ietf.org/html/draft-mcgrew-aead-aes-cbc-hmac-sha2-05. It uses an Authenticated Encryption scheme with Associated Data, following an Encrypt-then-MAC approach. That is, the plaintext is first encrypted, and the MAC is produced based on the resulting ciphertext.

In order to conceal patterns, AEAD_AES_256_CBC_HMAC_SHA_256 uses the Cipher Block Chaining (CBC) mode of operation, where an initial value is fed into the system named the initialization vector (IV). The full description of the CBC mode can be found at https://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf.

AEAD_AES_256_CBC_HMAC_SHA_256 computes a ciphertext value for a given plaintext value using the following steps.

Step 1: Generating the initialization vector (IV)

Always Encrypted supports two variations of AEAD_AES_256_CBC_HMAC_SHA_256:

  • Randomized

  • Deterministic

For randomized encryption, the IV is randomly generated. As a result, each time the same plaintext is encrypted, a different ciphertext is generated, which prevents any information disclosure.

When using randomized encryption: IV = Generate cryptographicaly random 128bits 

If there's deterministic encryption, the IV isn't randomly generated, but instead it's derived from the plaintext value using the following algorithm:

When using deterministic encryption: IV = HMAC-SHA-256( iv_key, cell_data ) truncated to 128 bits. 

Where iv_key is derived from the CEK in the following way:

iv_key = HMAC-SHA-256(CEK, "Microsoft SQL Server cell IV key" + algorithm + CEK_length) 

The HMAC value truncation is performed to fit one block of data as needed for the IV.As a result, deterministic encryption always produces the same ciphertext for a given plaintext value, which enables inferring whether two plaintext values are equal by comparing their corresponding ciphertext values. This limited information disclosure allows the database system to support equality comparison on encrypted column values.

Deterministic encryption is more effective in concealing patterns, compared to alternatives, such as using a pre-defined IV value.

Step 2: Computing AES_256_CBC Ciphertext

After computing the IV, the AES_256_CBC ciphertext is generated:

aes_256_cbc_ciphertext = AES-CBC-256(enc_key, IV, cell_data) with PKCS7 padding. 

Where the encryption key (enc_key) is derived from the CEK as follows.

enc_key = HMAC-SHA-256(CEK, "Microsoft SQL Server cell encryption key" + algorithm + CEK_length ) 

Step 3: Computing MAC

Subsequently, the MAC is computed using the following algorithm:

MAC = HMAC-SHA-256(mac_key, versionbyte + IV + Ciphertext + versionbyte_length) 

Where:

versionbyte = 0x01 and versionbyte_length = 1mac_key = HMAC-SHA-256(CEK, "Microsoft SQL Server cell MAC key" + algorithm + CEK_length) 

Step 4: Concatenation

Finally, the encrypted value is produced by concatenating the algorithm version byte, the MAC, the IV, and the AES_256_CBC ciphertext:

aead_aes_256_cbc_hmac_sha_256 = versionbyte + MAC + IV + aes_256_cbc_ciphertext 

Ciphertext Length

The lengths (in bytes) of particular components of AEAD_AES_256_CBC_HMAC_SHA_256 ciphertext are:

  • versionbyte: 1

  • MAC: 32

  • IV: 16

  • aes_256_cbc_ciphertext: (FLOOR (DATALENGTH(cell_data)/ block_size) + 1)* block_size, where:

    • block_size is 16 bytes

    • cell_data is a plaintext value

    Therefore, the minimal size of aes_256_cbc_ciphertext is 1 block, which is 16 bytes.

Thus, the length of ciphertext, resulting from encrypting a given plaintext values (cell_data), can be calculated using the following formula:

1 + 32 + 16 + (FLOOR(DATALENGTH(cell_data)/16) + 1) * 16 

For example:

  • A 4-byte long int plaintext value becomes a 65-byte long binary value after encryption.

  • A 2,000-byte long nchar(1000) plaintext values becomes a 2,065-byte long binary value after encryption.

The following table contains a complete list of data types and the length of ciphertext for each type.

Data TypeCiphertext Length [bytes]
bigint65
binaryVaries. Use the formula above.
bit65
charVaries. Use the formula above.
date65
datetime65
datetime265
datetimeoffset65
decimal81
float65
geographyN/A (not supported)
geometryN/A (not supported)
hierarchyidN/A (not supported)
imageN/A (not supported)
int65
money65
ncharVaries. Use the formula above.
ntextN/A (not supported)
numeric81
nvarcharVaries. Use the formula above.
real65
smalldatetime65
smallint65
smallmoney65
sql_variantN/A (not supported)
sysnameN/A (not supported)
textN/A (not supported)
time65
timestamp

(rowversion)

N/A (not supported)
tinyint65
uniqueidentifier81
varbinaryVaries. Use the formula above.
varcharVaries. Use the formula above.
xmlN/A (not supported)

.NET Reference

For details about the algorithms, discussed in this document, see the SqlAeadAes256CbcHmac256Algorithm.cs, SqlColumnEncryptionCertificateStoreProvider.cs, and SqlColumnEncryptionCertificateStoreProvider.cs files in the .NET Reference.

See also

  • Always Encrypted
  • Develop applications using Always Encrypted

I'm a seasoned expert in database security, particularly in the realm of encryption algorithms and mechanisms, with a focus on the Always Encrypted feature in SQL Server and Azure SQL Database. My depth of knowledge is rooted in practical experience and a comprehensive understanding of the intricate details involved in securing sensitive data.

The Always Encrypted feature utilizes two fundamental types of keys: Column Master Keys (CMK) and Column Encryption Keys (CEK). A CMK, functioning as a key encrypting key, is under the client's control and stored externally. It interacts with a CMK store provider, either embedded in the driver library or within the client application. Microsoft provides key store providers for Windows Certificate Store and hardware security modules (HSMs), while custom providers can also be integrated.

CEKs are content encryption keys protected by a CMK. Microsoft CMK store providers use RSA with Optimal Asymmetric Encryption Padding (RSA-OAEP) to encrypt CEKs, employing different hash functions based on the provider. Always Encrypted adheres to FIPS 140-2 validated cryptographic modules.

The data encryption algorithm employed by Always Encrypted is AEAD_AES_256_CBC_HMAC_SHA_256, derived from the specified draft. This algorithm uses Authenticated Encryption with Associated Data (AEAD) in an Encrypt-then-MAC approach. The Cipher Block Chaining (CBC) mode is utilized to conceal patterns, with an initialization vector (IV) generated based on encryption type.

The algorithm proceeds through multiple steps to generate the final encrypted value. The IV is generated differently for randomized and deterministic encryption. Randomized encryption involves a cryptographically random IV, while deterministic encryption derives the IV from the plaintext value.

The AEAD_AES_256_CBC_HMAC_SHA_256 algorithm computes the AES_256_CBC ciphertext, MAC, and ultimately produces the encrypted value by concatenating various components. The ciphertext length is determined by the plaintext value, following a specific formula.

The article provides a detailed breakdown of ciphertext lengths for various data types, offering practical insights into the impact of encryption on different types of data. This comprehensive coverage demonstrates the meticulous design and implementation of Always Encrypted, ensuring robust data security in SQL Server and Azure SQL Database.

For further reference, developers can explore the associated .NET files mentioned in the article, such as SqlAeadAes256CbcHmac256Algorithm.cs, SqlColumnEncryptionCertificateStoreProvider.cs, and SqlColumnEncryptionCertificateStoreProvider.cs, providing additional insights into the underlying algorithms and implementations.

Always Encrypted cryptography - SQL Server (2024)

FAQs

What is always encrypted in SQL Server? ›

Always Encrypted is a feature designed to protect sensitive data, such as credit card numbers or national/regional identification numbers (for example, U.S. social security numbers), stored in Azure SQL Database, Azure SQL Managed Instance, and SQL Server databases.

How do I decrypt an always encrypted column in SQL Server? ›

Enter your SQL Server credentials.
  1. Add the “Column Encryption Setting=enabled;” property in the Additional connection parameters text box.
  2. Click on 'Connect'. This will open the query designer page. ...
  3. The encrypted data will now be displayed as decrypted. ...
  4. References.
Nov 2, 2023

What is the difference between TDE and always encrypted? ›

To simplify: TDE secures all of the database files on disk, hence the term "at rest". Since encryption and decryption are done by the database engine, it's transparent to all clients. Always Encrypted is more granular, specific data elements/columns store encrypted data which requires a "key" to translate.

What is the difference between always encrypted and column level encryption? ›

Always encrypted is completely transparent to the applications. The client application needs to be heavily modified to support column-level encryption. An Always Encrypted-enabled driver needs to be installed on a client computer to handle encryption and decryption transparently.

Is SQL Server data encrypted by default? ›

Neither SQL data nor the server to client connection are encrypted by default. Most SQL/RDBMS do promise to encrypt the users' PASSWORD fields, but not anything else.

Which system database Cannot be encrypted explicitly in SQL Server? ›

Database encryption operations cannot be performed for 'master', 'model', 'tempdb', 'msdb' or 'resource' databases. However, it's important to realize that any successful encryption of a non-system database will cause TempDB to be encrypted automatically, to protect temporary objects.

How to convert encrypted data to decrypt in SQL Server? ›

Decrypt column level SQL Server encryption data
  1. In a query window, open the symmetric key and decrypt using the certificate. We need to use the same symmetric key and certificate name that we created earlier. ...
  2. Use the SELECT statement and decrypt encrypted data using the DecryptByKey() function.
Jan 14, 2020

How to decrypt AES in SQL? ›

SELECT AES_DECRYPT(AES_ENCRYPT('mytext','mykeystring'), 'mykeystring'); Explanation: The above MySQL statement decrypts the encrypted string 'mytext' using mykeystring and returns the original string mytext.

How to decrypt encrypted view in SQL Server? ›

To narrow down the list to encrypted views only, apply the appropriate filter. Once you have the list of encrypted views, you can choose a specific view to decrypt and save its description as a file. Click Execute to decrypt the view in the SQL Server database. Once the process is complete, click Finish.

Is it better to always encrypt data? ›

Finally, Always Encrypted protects the most sensitive data from privileged user attacks, malware that has compromised the database environments, and other threats against the data while it is in use. TDE works with SQL Server 2008 and above as well as Azure SQL Database, but requires SQL Server Enterprise Edition.

What are the disadvantages of TDE encryption? ›

One disadvantage of TDE is that it does not protect data in transit. Data is only encrypted when it is at rest in the database. If data is transmitted over a network, it can be intercepted and read by an attacker.

How do I turn off always encrypted? ›

To enable (disable) Always Encrypted:
  1. Open Connect To Server dialog (see Connect to a SQL Server instance for details).
  2. Select Options.
  3. Select the Always Encrypted tab. To enable Always Encrypted, select Enable Always Encrypted (column encryption). ...
  4. Select Connect.
Feb 28, 2023

What is the strongest cryptographic encryption? ›

Strongest Data Encryption Algorithms
  • TripleDES.
  • Twofish encryption algorithm.
  • Blowfish encryption algorithm.
  • Advanced Encryption Standard (AES)
  • IDEA encryption algorithm.
  • MD5 encryption algorithm.
  • HMAC encryption algorithm.
  • RSA security.
Jan 17, 2020

What are the disadvantages of column-level encryption? ›

Column Level Encryption Limitations
  • Performance Impact in typical transactions – 5-6 percent on average slower on accessing/updating an encrypted column versus plaintext column. ...
  • Cannot encrypt primary or foreign key fields without changes to existing programs.

Does SQL Server encrypt data at rest? ›

Transparent data encryption (TDE) encrypts SQL Server, Azure SQL Database, and Azure Synapse Analytics data files. This encryption is known as encrypting data at rest. To help secure a user database, you can take precautions like: Designing a secure system.

What is encrypt in SQL Server? ›

In SQL Server, encryption keys include a combination of public, private, and symmetric keys that are used to protect sensitive data. This section explains how to implement and manage encryption keys.

What is the data encryption standard in SQL Server? ›

TDE encrypts the entire database, including the actual data and the log files at rest. This process works seamlessly in the background without affecting the performance of the user program. TDE provides a transparent layer of security over the datbase with small changes in the actual database schema.

How do I know if SQL Server is encrypted? ›

Step 3: To check a database's encryption, right-click on it and choose “Properties” from the context menu. Step 4: In the Database Properties window, navigate to the “Options” page on the left-hand side. Step 5: Scrolling down “Encryption Enabled” property will be found.

Is My SQL database encrypted? ›

The mysql system tablespace contains the mysql system database and MySQL data dictionary tables. It is unencrypted by default. To enable encryption for the mysql system tablespace, specify the tablespace name and the ENCRYPTION option in an ALTER TABLESPACE statement.

Top Articles
4 Steps To Add Hector DAO To Your Metamask Wallet | Financially Independent Pharmacist
Encrypt and Decrypt Data in NodeJS
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 6568

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.