How To Get Started With Always Encrypted For Beginners - Part Two

In this post we will pick up where we left off in Part 1, if you haven’t read that please go back and do so.

Now that we have encrypted our columns, it’s time to take a look at how we decrypt them inside SQL Server Management Studio or through our applications. You’ll be surprised to see how easy it is.

Verify Your Setup

First, let’s verify that the table is still encrypted, and nothing changed after you ran through the Part 1 examples. To confirm, simply query sys.columns, script out the table, or query the data to check that the Birthdate column is still encrypted.

  1. USE[AdventureWorks2016CTP3]  
  2. GO  
  3. CREATE TABLE[HumanResources].[Employee_AE]([BusinessEntityID][intNOT NULL,   
  4.                                            [NationalIDNumber][nvarchar](15) NOT NULL,  
  5.   [LoginID][nvarchar](256) NOT NULL,  
  6.   [OrganizationNode][hierarchyid] NULL,  
  7.     [OrganizationLevel][smallintNULL,   
  8.       [JobTitle][nvarchar](50) NOT NULL,   
  9.       [BirthDate][date] ENCRYPTED WITH(COLUMN_ENCRYPTION_KEY = [CEK_Auto7],   
  10.                                        ENCRYPTION_TYPE = Deterministic,  
  11.                                        ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256'NOT NULL,   
  12.         [MaritalStatus][nchar](1) NOT NULL,   
  13.         [Gender][nchar](1) NOT NULL,  
  14.         [HireDate][dateNOT NULL,  
  15.           [SalariedFlag][dbo].[Flag] NOT NULL,   
  16.             [VacationHours][smallintNOT NULL,  
  17.       [SickLeaveHours][smallintNOT NULL,   
  18.         [CurrentFlag][dbo].[Flag] NOT NULL,  
  19.           [rowguid][uniqueidentifier] NOT NULL,   
  20.             [ModifiedDate][datetime] NOT NULLON[PRIMARY] GO  

You can also just SELECT and look at the data. Here you see the encrypted values for the data in the birthdate column.

  1. SELECT * FROM [AdventureWorks2016CTP3].[HumanResources].[Employee_AE]  

Check system tables

  1. SELECT  
  2.   DB_NAME() AS [database],  
  3. AS [table],  
  4. AS [column],  
  5.   encryption_algorithm_name,  
  6.   encryption_type,  
  7.   encryption_type_desc  
  8. FROM sys.columns c  
  9. JOIN sys.tables t  
  10.   ON t.object_id = c.object_id  
  11. WHERE c.Name = 'Birthdate'  
  12. AND = 'Employee_AE' 

Decrypt with SQL Server Management Studio

Viewing decrypted data within SQL Server Management Studio (SSMS) is very easy. SSMS uses .NET 4.6 and the modern SQL Server client, so you can pass in the necessary encryption options. SSMS uses the connection string to access the Master Key and return the data in its decrypted format.

First create a new SQL Connection and Click Options to expand the window.

Then go to the Additional Connections Parameters Tab of the login window and simply type column encryption setting = enabled. Then choose Connect.

Now try SELECT From your columns.

  1. SELECT * FROM [AdventureWorks2016CTP3].[HumanResources].[Employee_AE]  

If you did it correctly you will see the decrypted BirthDate column.

Now the reason this works is both the Column Key and Master Key are stored in the Windows Certificate Store of this SQL Server. The Master Key was setup in Part 1 in the Windows Certificate Store.

Decrypt with an Application

According to MSDN for the application to decrypt data the account that connects to the database must have the VIEW ANY COLUMN MASTER KEY DEFINITION and VIEW ANY COLUMN ENCRYPTION KEY DEFINITION database permissions. These permissions are required to access the metadata about Always Encrypted keys in the database.

Once those permissions are established all you must do is change your application connection string to include Column Encryption Setting=enabled. Below is an example using SQL Server integrated security.


  1. string connectionString = "Data Source=server63;   
  2. Initial Catalog=Clinic;   
  3. Integrated Security=true;   
  4. Column Encryption Setting=enabled";  
  5. SqlConnection connection = new SqlConnection(connectionString);  


Decrypting the data when you have the Master Key stored on your Database Server makes it easy, but it also gives access to the encrypted data to the DBA. Make sure when you are planning to use Always Encrypted you consider who you want to have access to the data and where you want to store the keys. There are many more layers of security you can add to this by defining those items. The example I gave in both Part 1 and Part 2 are the least complex and therefore not the most secure, but it gives you a beginner’s overview of how implement it. You need to examine your application to understand if it fits with in the current supported features of always encrypted.