Showing posts with label Sql Encryption. Show all posts
Showing posts with label Sql Encryption. Show all posts

Sunday, January 7, 2018

Encrypt and Decrypt string using SQL

Sample Code


 Declare   
 @myData nvarchar(max) = 'My data',  
 @seqKey nvarchar(20) = 'UniQKey07x@a',  
 @encryptedData varbinary(2000)  
 set @encryptedData = EncryptByPassPhrase(@seqKey, @myData)  
 print @encryptedData  
 print convert(nvarchar(max),DecryptByPassPhrase(@seqKey, @encryptedData ))--Decrypted data  

Output

 0x010000008076CB00D6FB7820D77D4B9C3768D596BA1812019E4CFCAEF9B190DAD462A3E3  
 My data