原文出处:https://www.cnblogs.com/BinBinGo/p/7171174.html?utm_source=itdadao&utm_medium=referral
--------加密函数-----------
CREATE FUNCTION dbo.EncryptByPassPhrasePwd(@password nvarchar(50))
RETURNS varbinary(max)
AS  
BEGIN 
    declare @pwd varbinary(max)
 SELECT @pwd = EncryptByPassPhrase(
 'www.baidu.com',            
 @password)
    return @pwd
END
---------解密函数----------
CREATE  FUNCTION dbo.DecryptByPassPhrasePwd(@password varbinary(max))
RETURNS nvarchar(max)
AS  
BEGIN 
    declare @pwd nvarchar(max)
 SELECT @pwd =CAST( DecryptByPassPhrase('www.baidu.com',@password)  as nvarchar(max))
    return @pwd
END
注意:www.baidu.com 是用于生成对称密钥的通行短语
select dbo.EncryptByPassPhrasePwd('test11') as result
select dbo.DecryptByPassPhrasePwd(0x01XXX) as result



本文转载:CSDN博客