数据库加密解密(函数实现)

EncryptByPassPhrasePwd

USE [cecaopsys]

GO

/****** Object:  UserDefinedFunction [dbo].[EncryptByPassPhrasePwd]    Script Date: 07/12/2017 17:17:45 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

//-----------加密函数-----------

ALTER FUNCTION [dbo].[EncryptByPassPhrasePwd](@password nvarchar(50))
RETURNS varbinary(max)
AS 
BEGIN
    declare @pwd varbinary(max)
 SELECT @pwd = EncryptByPassPhrase(
 'EPdRc2',           
 @password)
    return @pwd
END;

 

DecryptByPassPhrasePwd

USE [cecaopsys]

GO

/****** Object:  UserDefinedFunction [dbo].[DecryptByPassPhrasePwd]    Script Date: 07/12/2017 17:39:13 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

//---------解密函数----------
ALTER  FUNCTION [dbo].[DecryptByPassPhrasePwd](@password varbinary(max))
RETURNS nvarchar(max)
AS 
BEGIN
    declare @pwd nvarchar(max)
 SELECT @pwd =CAST( DecryptByPassPhrase('EPdRc2',@password)  as nvarchar(max))
    return @pwd
END

 

 

 

posted @ 2019-04-15 18:16  WhatAreWords  阅读(917)  评论(0编辑  收藏  举报