Encryption and Decryption By Password in SQL

Encryption and Decryption

  • Encryption and Decryption Function.

Encrypt Function :-

Create Function dbo.Fn_ENCRYPT(@str varchar(max))
returns varbinary(8000)
as begin
declare @obj varbinary(8000)
set @obj = ENCRYPTBYPASSPHRASE(‘Bhargav Patel’,@str)
return (@obj)
end

Decrypt Function :-

Create Function dbo.Fn_DECRYPT(@str varbinary(8000))
returns varchar(max)
as begin
declare @obj  varchar(max)
set @obj = DECRYPTBYPASSPHRASE(‘Bhargav Patel’,@str)
return (@obj)
end

Use of above Function

SELECT dbo.Fn_ENCRYPT(‘SQL SERVER’)

OUTPUT :

Encryption

SELECT dbo.Fn_DECRYPT

(0x01000000D898AC04CE7777E7A45D99912FB70CB10B559B83BF7ED253AB43B9FF022008E7)

OUTPUT :

Decryption

Write a Comment

Your email address will not be published. Required fields are marked *