Always Encrypted is a client-side encryption feature of Microsoft SQL Server and Azure SQL that protects selected columns so that plaintext and encryption keys never reach the database engine. In database security, it addresses a threat that server-side encryption cannot: a privileged administrator or compromised server that can read data in memory or in query results.
The feature was introduced in SQL Server 2016 and extended with secure enclaves in SQL Server 2019. It is one of several encryption options in Databases, and its defining property is the separation of duties between those who own the data and those who operate the server.
How Always Encrypted keeps keys away from the server
Always Encrypted works by moving encryption and decryption into the client driver, such as Microsoft.Data.SqlClient, the ODBC driver or the JDBC driver. When an application connects with the setting Column Encryption Setting=Enabled, the driver transparently encrypts parameters that target protected columns and decrypts results before handing them to the application.
The scheme relies on a two-level key hierarchy. A column encryption key (CEK) encrypts the actual data, and a column master key (CMK) encrypts the CEK. The database stores only the encrypted CEK value and metadata that points to the CMK location; the CMK itself stays in a trusted key store that the server cannot access.
The following table lists the components and where each one resides.
| Component | Purpose | Where it is stored |
|---|---|---|
| Column master key | Protects one or more column encryption keys | Windows Certificate Store, Azure Key Vault or an HSM |
| Column encryption key | Encrypts the data in protected columns | Database, only in encrypted form |
| CMK metadata | Records the key store provider and key path | Database system catalog |
| CEK metadata | Links each CEK to its CMK and encrypted value | Database system catalog |
| Enabled client driver | Retrieves keys, encrypts and decrypts values | Application host |
Data is encrypted with the algorithm AEAD_AES_256_CBC_HMAC_SHA_256, which combines AES-256 in CBC mode with an HMAC-SHA-256 authentication tag. The tag means that tampered ciphertext is detected at decryption time rather than silently returning corrupted values.
Deterministic and randomized encryption types
Every protected column uses one of two encryption types, and the choice defines which queries remain possible. Deterministic encryption always produces the same ciphertext for the same plaintext, while randomized encryption uses a random initialization vector, so identical values look different each time.
| Property | Deterministic | Randomized |
|---|---|---|
| Same input, same ciphertext | Yes | No |
| Equality search and joins | Supported | Only with secure enclaves |
| Indexing | Supported | Only with secure enclaves |
| Pattern leakage | Reveals repeated values | Minimal |
| Typical columns | National ID, account number | Diagnosis, salary, free text |
Deterministic encryption trades confidentiality for functionality. An attacker who sees the ciphertext can still count how often each value occurs, which is dangerous for low-cardinality columns such as gender, blood type or a yes/no flag. Deterministic columns also require a binary BIN2 collation for character data, which affects sorting and comparison behavior.
Secure enclaves and rich computation
Always Encrypted with secure enclaves extends the feature so that the server can process encrypted data inside a protected memory region called an enclave. The client driver sends the CEK to the enclave over a secure channel after attestation confirms that the enclave runs genuine, unmodified code.
Inside the enclave, the engine can decrypt values to evaluate range comparisons, pattern matching with LIKE and sorting, and it can perform in-place encryption of existing columns without moving all data to the client. Code and data outside the enclave, including the rest of the SQL Server process, still see only ciphertext.
The enclave technology and attestation method depend on the platform, as the next table shows.
| Platform | Enclave technology | Attestation |
|---|---|---|
| SQL Server 2019 and later | Virtualization-based security (VBS) | Host Guardian Service or none |
| Azure SQL Database | VBS enclaves or Intel SGX | Microsoft Azure Attestation for SGX |
| Without enclaves | Not applicable | Not applicable |
Enclaves widen the attack surface slightly, because a flaw in the enclave or its attestation could expose plaintext. VBS enclaves without attestation protect against database administrators but offer weaker guarantees against an operating system administrator.
How it compares with other database encryption options
Always Encrypted differs from server-side mechanisms in who holds the keys and when data is in plaintext. Transparent data encryption protects files at rest, while column-level encryption with server-managed keys still lets the engine decrypt data on request.
| Mechanism | Protects against | Data visible to the engine |
|---|---|---|
| Always Encrypted | Malicious or compromised server operators | Never in plaintext outside enclaves |
| Transparent data encryption | Theft of data files and backups | Yes, decrypted in memory |
| Column-level encryption | Unauthorized readers of specific columns | Yes, when keys are opened |
| Dynamic data masking | Casual exposure in query results | Yes, masking is presentation only |
| Row-level security | Access to rows outside a user’s scope | Yes, filtering is policy based |
These mechanisms are complementary rather than alternatives. A common pattern combines transparent data encryption for whole-database protection at rest with Always Encrypted for the few columns that hold the most sensitive identifiers. Comparable client-side designs exist elsewhere, such as client-side field level encryption and Queryable Encryption in document databases.
Limitations and common mistakes
Always Encrypted imposes significant functional restrictions, and most deployment problems come from underestimating them. Without enclaves, the server cannot compute on encrypted values, so arithmetic, aggregation, full-text search and most string functions on protected columns fail or must move to the application.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Operand type clash error | Literal value sent instead of a parameter | Use parameterized queries |
| Application reads ciphertext | Column encryption setting not enabled | Enable it in the connection string |
| Key access denied | Client identity lacks CMK permissions | Grant key store permissions to the client |
| Slow first queries | Metadata and key lookups per query | Rely on driver key caching |
| Frequency analysis risk | Deterministic type on low-cardinality data | Use randomized encryption |
- Key rotation of a CMK is relatively cheap, but rotating a CEK requires re-encrypting every value in the affected columns.
- Encrypted columns are larger than plaintext, which affects storage, row size and index design.
- Tools and reports that query the database directly see only binary ciphertext unless they use an enabled driver with key access.
- Losing the CMK means permanent loss of the protected data, so key backup is a critical operational duty.
Put simply
Always Encrypted is like keeping valuables in a locked box inside a bank vault, while only the owner holds the key. The bank staff look after the vault, move boxes around and keep records, but they cannot open the boxes.
In a database, the application holds the key and locks sensitive values before sending them. The server stores and returns the locked values without ever reading them. The result is that even the people who run the database cannot see the protected information.
In practice
A regional hospital outsources the administration of its patient database to an external service provider. Regulators require that outside administrators cannot read diagnoses or national identification numbers. The hospital stores its column master key in a cloud key vault that only the clinical application can access.
The national ID column uses deterministic encryption, so the admissions system can still look up patients by exact match. The diagnosis column uses randomized encryption, because it is displayed but never searched. Developers convert all ad hoc SQL to parameterized queries, which the driver needs to encrypt values.
After deployment, the provider continues to perform backups, index maintenance and performance tuning, yet every query it runs against those columns returns only ciphertext. The audit that follows confirms that sensitive fields remain unreadable to administrators, which satisfies the separation of duties requirement.