Skip to content

Instantly share code, notes, and snippets.

@JustinMcNamara74
Last active August 29, 2015 14:18
Show Gist options
  • Save JustinMcNamara74/ec1fd320f224c89fc111 to your computer and use it in GitHub Desktop.
Save JustinMcNamara74/ec1fd320f224c89fc111 to your computer and use it in GitHub Desktop.
#MSSQL Creates all items necessary for SQL Server Encryption/Decryption
/**
A few notes:
- Remember the DB Master Key!!
- When creating certificates/keys be descriptive, as there may be many on your instance of SQL Server
**/
IF (select Count(*) from sys.symmetric_keys where name like '%DatabaseMasterKey%') = 0
BEGIN
CREATE master key Encryption by password = 'SomePassword';
END
IF (select Count(*) from sys.certificates where name = 'CertificateName') = 0
BEGIN
CREATE CERTIFICATE CertificateName with subject = 'Description Of Encryption';
END
IF (select count(*) from sys.symmetric_keys where name = 'EncrytionKeyName') = 0
BEGIN
-- Algorithm Options: DES,Triple DES,TRIPLE_DES_3KEY,RC2,RC4,128-bit RC4,DESX,128-bit AES,192-bit AES,256-bit AES.
CREATE symmetric key EncryptionKeyName with algorithm=TRIPLE_DES Encryption by certificate CertificateName;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment