An EKM provider can be used for column-level encryption and decryption. This chapter shows how to use the SecurityServer EKM provider as a column-level encryption and decryption engine.
-
To demonstrate encryption and decryption a table demo will be created first. Consider here that for cryptographic keys to be successfully used, they have to be generated within the same database as the table entries which you wish to encrypt.
|
SQL Statement |
|
SQL
|
-
New rows can be inserted like in the next SQL statement. This statement uses a symmetric column encryption for the column secret.
|
SQL Statement |
|
SQL
|
-
In the same way an asymmetric encryption could be used.
|
SQL Statement |
|
SQL
|
EncryptByAsymKey returns NULL if the input exceeds a certain number of bytes, depending on the algorithm.
The limits are:
-
a 2048 bit key can encrypt up to 245 bytes
Encryption and decryption with an asymmetric key are very costly compared with encryption and decryption with a symmetric key.
-
To show the decrypted value of an encrypted column the next statements can be used. This decrypts the symmetric encrypted column address and shows all stored rows of this table:
|
SQL Statement |
|
SQL
|
-
A decryption of asymmetric column can be achieved similar to the decryption of symmetric encrypted column:
|
SQL Statement |
|
SQL
|