Always Encrypted: Deterministic vs Randomized

Overview

Always Encrypted protects sensitive data such that the database engine never sees plaintext values. Two encryption types are available for column encryption:

When to Use Deterministic Encryption

Deterministic encryption enables equality searches, grouping, and joining on encrypted columns because identical plaintext values map to identical ciphertext.

-- Example: Find rows with a specific SSN
SELECT *
FROM dbo.Customers
WHERE EncryptedSSN = EncryptByKey(Key_GUID('CEK_Deterministic'), N'123‑45‑6789');

When to Use Randomized Encryption

Randomized encryption provides stronger security guarantees by adding randomness (IV) to each encryption operation, making ciphertext analysis infeasible.

-- Example: Insert a new row with randomized encryption
INSERT INTO dbo.Employees (EmployeeId, EncryptedSalary)
VALUES (101, 
  EncryptByKey(Key_GUID('CEK_Randomized'), CONVERT(varbinary, 85000.00))
);

Comparison Table

FeatureDeterministicRandomized
SearchabilityEquality queries supportedOnly exact match after decryption
IndexingCan create non‑clustered indexesIndexes not allowed
SecurityVulnerable to frequency analysisHigher confidentiality
PerformanceFaster reads for searchable columnsHigher CPU overhead on writes
Use CasesLookup tables, foreign keys, deduplicationHighly sensitive data such as credit card numbers

Best Practices

  1. Use deterministic encryption only for columns that require search or join operations.
  2. Prefer randomized encryption for columns that store highly confidential data and do not need to be searchable.
  3. Rotate column encryption keys regularly using ALTER COLUMN ENCRYPTION KEY.
  4. Leverage client‑side drivers that support Always Encrypted (e.g., ADO.NET, JDBC).

Related Articles