Using CAKM for Microsoft SQL Server EKM Provider
Once the CAKM for Microsoft SQL Server EKM Provider is installed and EKM is enabled, the database user accesses the provider using SQL queries.
Viewing the Provider Properties
To view the provider properties, execute the following query:
Note
The provider_id
fetched here can be used to query database for the supported algorithms (in the next section).
Viewing the Supported Algorithms
To view the supported algorithms, execute the following query:
For example:
Creating a Key on CipherTrust Manager
The below command creates a key on the CipherTrust Manager and opens its corresponding key in the database. Once the key in the database is open, you can use it for cryptographic operations.
To create a new asymmetric key on the CipherTrust Manager, execute the following statement:
For example:
You'll need to modify this statement to match your key name and preferred algorithm. To create a symmetric key, the statement must start with CREATE SYMMETRIC KEY
.
Note
By default, the new key created using CAKM for Microsoft SQL Server EKM provider is non-exportable. You can make it exportable from the CipherTrust Manager.
Opening an Existing Key in the Database
When you want to access a key that already exists on the CipherTrust Manager, you'll need to open that key in the database.
To open an asymmetric key in the database, execute the following statement:
You'll need to modify this statement to match your key name. To open a symmetric key, the statement must start with CREATE SYMMETRIC KEY
.
Note
To use a versioned key, create a versioned asymmetric key on the CipherTrust Manager and then use the above statement to create a key in Microsoft SQL Server.
Viewing All Keys in the Database
To view all keys currently in the database, execute the following queries:
Viewing All of a User’s Keys on the CipherTrust Manager
To view all of the user's keys on the CipherTrust Manager, execute the following query:
Dropping a Key from the Database
To drop an asymmetric key from the database, execute the following statement. This will remove the key only from the database. The key will remain on the CipherTrust Manager.
For example:
To drop a symmetric key, the statement must start with DROP SYMMETRIC KEY
.
Dropping a Key from the CipherTrust Manager
To drop a key from the database and remove it from the CipherTrust Manager, execute the following statement:
To drop a symmetric key, the statement must start with DROP SYMMETRIC KEY
.
Encrypting and Decrypting Table Column
In the examples in this section, the table used is created as below:
You can use either of the following two options while using symmetric keys for column encryption with the EncryptBy function:
On the CipherTrust Manager, create a symmetric key. This key can be used in all data encrypt/decrypt operations on the CipherTrust Manager unless 'Key Cache' is enabled.
On the CipherTrust Manager, create a symmetric key protected by an asymmetric key. This key can be used in all data encrypt/decrypt operations locally by the Microsoft SQL Server’s crypto library and only encryption/decryption of the symmetric key by the asymmetric key will be performed on the CipherTrust Manager resulting in improved performance.
Encrypting Data
To encrypt data, call the following procedures:
EncryptByAsymKey: for encryption by asymmetric keys.
EncryptByKey: for encryption by symmetric keys.
For example:
To encrypt with an asymmetric key, execute the following statement:
To encrypt with a symmetric key, execute the following statement:
Encrypting Existing Data
If you want to encrypt existing data in a table, use the below statements.
To encrypt with the symmetric key:
For example:
To encrypt with asymmetric key:
For example:
Decrypting Data
To decrypt data, call the following queries:
DecryptByAsymKey: for decryption by asymmetric keys.
DecryptByKey: for decryption by symmetric keys.
For example:
To decrypt with an asymmetric key, execute the following query:
To decrypt with a symmetric key, execute the following query:
Note
If you are using versioned keys for column encryption in the CipherTrust Manager, do not retire the version with which the data has been encrypted.
Dropping CAKM for Microsoft SQL Server EKM Provider
Drop the credential by executing the following statements:
Drop the CAKM for Microsoft SQL Server EKM Provider by executing the following statement:
Note
Once the session is created with the CipherTrust Manager, Microsoft SQL Server EKM does not close the connection. When CAKM for Microsoft SQL Server EKM provider is disabled or dropped then it closes the connection.