encrypt and decrypt in sql

Encryption, Decryption in Sql
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- encrypt function

CREATE function [dbo].[Encrypt](@str nvarchar(max)) 
  returns varbinary(max)
as
begin
declare @encryptedValue varbinary(max)
  SET @encryptedValue  = ENCRYPTBYPASSPHRASE('hDfR$h:)opK;@$ty&*$5rWER$&',@str)
  return @encryptedValue
end

-- decrypt function

CREATE function [dbo].[Decrypt](@str varchar(max)) 
  returns nvarchar(max)
as
begin
declare @decryptedValue nvarchar(max)
Set @decryptedValue = DECRYPTBYPASSPHRASE('hDfR$h:)opK;@$ty&*$5rWER$&',@str)
return @decryptedValue
end

Post a Comment

0 Comments