Friday, December 22, 2017

SQL SERVER - How encrypt/decrypt text with symmetric key

This is example using the easy symmetric TRIPLE DES cipher (128 bit).
First parameter both functions is key (must be same in both functions for good result).
select encryptByPassPhrase( 'abc', 'This is a text' ); 

select cast( decryptByPassPhrase( 'abc', 
cast( 0x0100000020125E55A80E96076336C470EA49C009E8F8C1675CDEEBFE663A01D217F19F8B as 
varbinary(100) ) ) as varchar(100) );
Output:
-------------------------------------------------------------------------------------
0x0100000020125E55A80E96076336C470EA49C009E8F8C1675CDEEBFE663A01D217F19F8B

(1 row(s) affected)

-------------------------------------------------------------------------------------
This is a text

(1 row(s) affected)

No comments:

Post a Comment