Encrypt data with a passphrase using the TRIPLE DES algorithm with a 128 key bit length.

DECLARE @plain_text NVARCHAR(1000)
SET @plain_text = 'Hello123'

DECLARE @passphrase NVARCHAR(1000)
SET @passphrase = N'My Passphrase';

DECLARE @encrypted_string VARBINARY(MAX)
SET @encrypted_string = EncryptByPassPhrase(@passphrase, @plain_text)

DECLARE @decrypted_string NVARCHAR(1000)
SET @decrypted_string = DecryptByPassPhrase(@passphrase, @encrypted_string);

PRINT @plain_text 

PRINT @encrypted_string

PRINT @decrypted_string

Sources:

https://docs.microsoft.com/en-us/sql/t-sql/functions/encryptbypassphrase-transact-sql?view=sql-server-2017

Last modified: August 22, 2019

Author

Comments

Write a Reply or Comment