鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 网站安全 > 加密解密 > >

[易飞]密码加密解密函数

来源:互联网 作者:佚名 时间:2015-10-09 06:13
-- =============================================-- SQL 加密 用户 密码 -- =============================================CREATE FUNCTION EncodePwd( @user nvarchar(32), @userPwd nvarchar(32))RETURNS nvarchar(128)ASBEGINDECLARE @fnil nvarchar(1
-- =============================================-- SQL 加密用户密码-- =============================================CREATE FUNCTION EncodePwd( @user nvarchar(32), @userPwd nvarchar(32))RETURNS nvarchar(128)ASBEGINDECLARE @fnil nvarchar(128),@FF1 NVARCHAR(128)SET @fnil = '''(&.&!''%&{1}quot;''&)" ",&)$(%#$-$#$" 'SET @FF1 = ' !"#$%&''()*+,-./'DECLARE @n int, @i int, @d intDECLARE @Result nvarchar(100)SET @i = LEN(@user)SET @Result = SUBSTRING(@fnil,(@i-1)*2+1, 30-(@i-1)*2)SET @n = @i-1WHILE(@n>=0)BEGIN SET @i = (ASCII(SUBSTRING(@user,@n+1,1)) - 32) % 16 SET @d = (ASCII(SUBSTRING(@user,@n+1,1)) - 32) / 16 + 1 SET @Result = @Result + CHAR(32 + @d + 1) + SUBSTRING(@FF1,@i+1,1) SET @n = @n-1ENDDECLARE @n1 int , @n2 intDECLARE @FStr1 NCHAR(1), @FStr2 NCHAR(1), @FStr3 NCHAR(1), @Fchar1 NCHAR(1)SET @i =1WHILE(@i<=LEN(@userPwd))BEGIN IF(@i<=4) BEGIN SET @FStr1 = SUBSTRING(@userPwd,@i,1) SET @FStr2 = SUBSTRING(@Result,@i,1) SET @FStr3 = SUBSTRING(@Result,28+@i,1) SET @n1 = ((ASCII(SUBSTRING(@userPwd,@i,1)) - 32) % 8) SET @n2 = ((ASCII(SUBSTRING(@userPwd,@i,1)) - 32) / 16) SET @Fchar1 = CHAR(@n2 * 16 + 32) SET @n2 = ASCII(@FStr2) ^ ASCII(@FStr1) SET @n2 = (@n2 & 0x0F) + 0x20 SET @FStr2 =CHAR(@n2) SET @FStr3 = CHAR(ASCII(@Fchar1) + ((ASCII(@FStr3) + ASCII(@Fchar1)) % 16)) SET @Result = SUBSTRING(@Result,1, @i-1) + @FStr2 + Substring(@Result,@i + 1, 31 - @i+1) SET @Result = Substring(@Result,1, 28 + @i-1) + @FStr3 + Substring(@Result,29 + @i, 3 - @i+1) END ELSE BEGIN SET @FStr1 = SUBSTRING(@userPwd,@i,1) SET @FStr2 = SUBSTRING(@Result,@i,1) SET @FStr3 = SUBSTRING(@Result,@i-4,1) SET @n1 = ((ASCII(SUBSTRING(@userPwd,@i,1)) - 32) % 16) SET @n2 = ((ASCII(SUBSTRING(@userPwd,@i,1)) - 32) / 16) SET @Fchar1 = CHAR(@n2 * 16 + 32) SET @n2 = ASCII(@FStr2) ^ ASCII(@FStr1) SET @n2 = (@n2 & 0x0F) + 0x20 SET @FStr2 =CHAR(@n2) SET @FStr3 = CHAR(ASCII(@Fchar1) + ((ASCII(@FStr3) + ASCII(@Fchar1)) % 16)) SET @Result = SUBSTRING(@Result,1, @i-1) + @FStr2 + Substring(@Result,@i + 1, 31 - @i+1) SET @Result = Substring(@Result,1, @i-4-1) + @FStr3 + Substring(@Result,@i-3, 35 - @i+1) END SET @i = @i+1 ENDRETURN @ResultENDGO 
-- =============================================-- SQL 解密用户密码-- =============================================CREATE FUNCTION DecodePwd( @user nvarchar(32), @userPwd nvarchar(128))RETURNS nvarchar(128)ASBEGINDECLARE @Return NVARCHAR(100)SET @Return =''DECLARE @KeyLen INT,@i INT,@n1 INT,@n2 INTDECLARE @FStr1 CHAR(1),@FStr2 CHAR(1),@FStr3 CHAR(1),@FStr4 CHAR(1)DECLARE @fnil nvarchar(128),@FF1 NVARCHAR(128)SET @fnil = '''(&.&!''%&{1}quot;''&)" ",&)$(%#$-$#$" 'SET @FF1 = ' !"#$%&''()*+,-./'DECLARE @n int, @d intDECLARE @Result nvarchar(100)SET @i = LEN(@user)SET @Result = SUBSTRING(@fnil,(@i-1)*2+1, 30-(@i-1)*2)SET @n = @i-1WHILE(@n>=0)BEGIN SET @i = (ASCII(SUBSTRING(@user,@n+1,1)) - 32) % 16 SET @d = (ASCII(SUBSTRING(@user,@n+1,1)) - 32) / 16 + 1 SET @Result = @Result + CHAR(32 + @d + 1) + SUBSTRING(@FF1,@i+1,1) SET @n = @n-1ENDSET @KeyLen =0SET @i =28WHILE(@i>=1)BEGIN IF(SUBSTRING(@userPwd,@i,1)<>SUBSTRING(@Result,@i,1)) BEGIN SET @KeyLen = @i BREAK; END SET @i = @i-1ENDIF(@KeyLen =0) RETURN ''SET @i = @KeyLenWHILE(@i>=1)BEGIN IF(@i<=4) BEGIN SET @FStr1 = SUBSTRING(@Result,@i,1) SET @FStr3 = SUBSTRING(@userPwd,@i,1) SET @FStr4 = SUBSTRING(@userPwd,32-4+@i,1) SET @n1 = ASCII(@FStr1) ^ ASCII(@FStr3) SET @n2 = ((ASCII(@FStr4)-32) / 16) SET @Return = CHAR((16*@n2)+32+@n1) + @Return SET @FStr4 = CHAR((ASCII(@FStr4) % 16)+32) SET @userPwd = SUBSTRING(@userPwd,1,32-4+@i-1)+@FStr4+SUBSTRING(@userPwd,32-4+@i+1,4-@i) END ELSE BEGIN SET @FStr1 = SUBSTRING(@Result,@i,1) SET @FStr3 = SUBSTRING(@userPwd,@i,1) SET @FStr4 = SUBSTRING(@userPwd,@i-4,1) SET @n1 = ASCII(@FStr1) ^ ASCII(@FStr3) SET @n2 = ((ASCII(@FStr4)-32) / 16) SET @Return = CHAR((16*@n2)+32+@n1) + @Return SET @FStr4 = CHAR((ASCII(@FStr4) % 16)+32) SET @userPwd = SUBSTRING(@userPwd,1,@i-4-1)+@FStr4+SUBSTRING(@userPwd,@i-4+1,32-@i+4) END SET @i = @i-1ENDRETURN @ReturnENDGO 


 

网友评论
<