Encrypt data with a passphrase using the TRIPLE DES algorithm with a 128 key bit length if you can trust the database with the key.


DECLARE @SECRET VARCHAR(256)
DECLARE @ENC_SECRET VARBINARY(256)
DECLARE @DEC_SECRET VARCHAR(256)

SET @SECRET = 'TrustInGod'
-- @passphrase - a passphrase from which to generate a symmetric key.
-- @cleartext - the cleartext to be encrypted, maximum size is 8,000 bytes.
-- @add_authenticator - Indicates whether an authenticator will be encrypted together with the cleartext. 1 if an authenticator will be added.
SET @ENC_SECRET = EncryptByPassPhrase('BANGTECH', @SECRET, 2) 
PRINT @ENC_SECRET

SET @DEC_SECRET = DecryptByPassPhrase('BANGTECH', @ENC_SECRET, 2) 
PRINT @DEC_SECRET