Database Security encryption technique
Purpose:
Due to the increase in number of data crimes in the world, Database Security is a major concern in organizations today. Especially, organization who is handling sensitive data like finance, health and security.
They are keen to prevent data using encryption technique. SQL encryption technique is most popular today. SQL Server provides a variety of encryption approaches.
Symmetric encryption:
This algorithm either takes unencrypted data and return encrypted data, or they take encrypted data and return unencrypted data and work in both way. It can use key to encrypt data in SQL table. Symmetric algorithm is faster than the asymmetric encryption.
Asymmetric key encryption: Asymmetric key technique is different from the symmetric key technique. It is a system in which the sender and the receiver of a message have a pair of cryptographic keys – a public key and a private key to encrypt and decrypt the message. This is a relatively complex system where the sender can use his key to encrypt the message but he cannot decrypt it. The receiver, on the other hand, can use his key to decrypt the message but he cannot encrypt it.
Symmetric encryption algorithm types are the following:
- DES (DES)
- Triple DES with 128 bit key (TRIPLE_DES)
- Triple DES with 192 bit key (DESX)
- RC2 (RC2)
- RC4 (RC4)
- RC4 with 128 bit key (RC4_128)
- AES with 128 bit key (AES_128)
- AES with 192 bit key (AES_192)
- AES with 256 bit key (AES_256)
This function applies 48 bit keys and 32 Bits Ri to produce a 32 Bit output and is is made up to four operations,
- an XOR
- an expansion permutation
- a group of S-boxes
- a straight permutation
TripleDES: It is the improved version of des algorithm. DES uses 56 bits of a 64-bit key to encrypt messages in fixed-sized blocks of data and Triple DES use 3 DES.
ADVANTAGE: Key size of 3DES is larger than DES.
DISADVANTAGE: The process of 3DES is very slow.
RC2:
It is the replacement of the DES. RC2 encrypts data in 64-bit blocks and has a variable key size of 8 to 128 bits in 8-bit increments. Encryption algorithms strength lies in the length of its keys. If size of key is big then encryption algorithm is more strong.
Elaborate Triple Des with 192 bit in more details. This algorithm is considered more secure and faster.
Steps to create symmetric key and use in database encryption: Before creating the symmetric key we need to create master key and a certificate, which act as protectors of our symmetric key store.
Create a Database Master Key
- CREATE MASTER KEY ENCRYPTION BY PASSWORD = ‘myStrongPassword’
- CREATE CERTIFICATE MyCertificateName
- WITH SUBJECT =’Label for Certificate’
Create a Symmetric Key
- CREATE SYMMETRIC KEY MySymmetrickeyName
- WITH ALGORITHM = TRIPLE_DES ENCRYPTION
- BY CERTIFICATE MyCertificateName
Query to open Symmetric key
- OPEN SYMMETRIC KEY MySymmetricKeyName
- DECRYPTION BY CERTIFICATE MyCertificateName
Encrypting Data Query
- DECLARE @Result varbinary(256)
- SET @Result = ENcryptByKey(Key_GUID(‘MySymmetricKeyName’)),
- @ValueToEncrypt)
- Decrypt Data Query
- DECLARE @Result varbinary(max)
- SET @Result = ENcryptByKey(Key_GUID(‘MySymmetricKeyName’)),
- @ValueToEncrypt)
Step 1: Query to create user table for implementing encryption process.
Step 2: Query to insert data in user table.
Step 3: Create a master key in database using below query.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'EncryptionUser@123'
Step 4: Now create certificate in same database using below query.
CREATE CERTIFICATE UserTestCert WITH SUBJECT = 'EncryptionUserCert'
Step 5: Create symmetric key.
CREATE SYMMETRIC KEY EncryptTableKey WITH ALGORITHM = TRIPLE_DES ENCRYPTION
BY CERTIFICATE UserTestCert
Step 6: After creating symmetric key in database use that key to encrypt and decrypt the data.
Step 7: After executing the update query data is in encrypted mode.
Step 8: Query to decrypt the data.
Queries to drop the key and certificate from database,
- CLOSE SYMMETRIC KEY EncryptTableKey
- GO
- DROP SYMMETRIC KEY EncryptTableKey
- GO
- DROP CERTIFICATE EncryptionUserCert
- GO
- DROP MASTER KEY
- GO
- Provide security to application from unauthorized user.
- Identity Theft Protection
- Used for highly sensitive data like defense, financial, health.
- More damage if keys or certificate compromised.
- Slow in performance
Encryption is a very important security feature of SQL Server. Asymmetric key has a stronger encryption approach. Stronger encryption is slower to process and take longer time to encrypt the data. When there is a huge amount of data to encrypt, it is suggested to encrypt it using a symmetric key. Also, it is faster than asymmetric key. It is also recommended to compress data before encryption, as encrypted data cannot be compressed.
Santhakumar MunuswamyPosted Jan 17, 2016, 2:27 PM
Thanks for nice share
Gowtham KPosted Jan 16, 2016, 11:30 PM
Good One, Thanks for sharing:)
Shubham KumarPosted Jan 16, 2016, 1:05 PM
Nice one!! keep share
Ravi MaheshwariPosted Jan 16, 2016, 2:40 AM
thank you
Yashwant VishwakarmaPosted Jan 16, 2016, 1:39 AM
awesome dude, thanks for sharing !!
Pankaj Kumar ChoudharyPosted Jan 15, 2016, 7:42 PM
Great Explanation..........
Debasis SahaPosted Jan 15, 2016, 3:43 PM
Good One..