加入收藏
联系我们
关于我们
 您现在的位置: 亿聪 >> 网络学院 >> 网络编程 >> 其它 >> 正文  
  MD5算法的T-SQL实现(FOR SQL2000)       ★★★
MD5算法的T-SQL实现(FOR SQL2000)
[ 作者:Rambo Qian    转贴自:aspsky    点击数:34409    更新时间:2003/8/28    文章录入:亿聪 ]
   @sOrigMess    VARCHAR(8000)  = ''
)
RETURNS @tWordArray TABLE([ID] INT IDENTITY(0,1),[Word] INT)
WITH ENCRYPTION
AS
BEGIN
  IF @sOrigMess IS NULL
    SET @sOrigMess = ''

  DECLARE @iLenOfMess      INT
  DECLARE @iWordArrayLen    INT
  DECLARE @iPosOfWord      INT
  DECLARE @iPosOfMess      INT
  DECLARE @iCountOfWord    INT

  SET @iLenOfMess = LEN(@sOrigMess)
  SET @iWordArrayLen = ((@iLenOfMess + 8)/64 + 1) * 16
  SET @iCountOfWord = 0
  WHILE(@iCountOfWord<@iWordArrayLen)
  BEGIN
    INSERT INTO @tWordArray([Word]) VALUES(0)
    SET @iCountOfWord = @iCountOfWord + 1
  END

  SELECT @iPosOfMess = 0, @iPosOfWord = 0, @iCountOfWord = 0
  WHILE(@iPosOfMess < @iLenOfMess)
  BEGIN
    SELECT @iCountOfWord = @iPosOfMess / 4, @iPosOfWord = @iPosOfMess % 4
    UPDATE @tWordArray
      SET [Word] = [Word] | dbo.MD5_LShift(UNICODE(SUBSTRING(@sOrigMess,@iPosOfMess+1,1)),@iPosOfWord*8)
      WHERE [ID] = @iCountOfWord
    SET @iPosOfMess = @iPosOfMess + 1
  END
  
  SELECT @iCountOfWord = @iPosOfMess / 4, @iPosOfWord = @iPosOfMess % 4
  UPDATE @tWordArray
    SET [Word] = [Word] | dbo.MD5_LShift(0x80,@iPosOfWord*8)
    WHERE [ID] = @iCountOfWord

  UPDATE @tWordArray
    SET [Word] = [Word] | dbo.MD5_LShift(@iLenOfMess,3)
    WHERE [ID] = @iWordArrayLen - 2
  UPDATE @tWordArray
    SET [Word] = [Word] | dbo.MD5_RShift(@iLenOfMess,29)
    WHERE [ID] = @iWordArrayLen - 1
  RETURN
END
GO

IF EXISTS(SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MD5_WordToHex]') AND xtype IN(N'FN', N'IF', N'TF'))
  DROP FUNCTION [dbo].[MD5_WordToHex]
GO
/*****************************************************************************
* Name: MD5_WordToHex
* Description: MD5_WordToHex
*****************************************************************************/
CREATE FUNCTION dbo.MD5_WordToHex(
   @iValue    INT
)
RETURNS CHAR(8)
WITH ENCRYPTION
AS
BEGIN
  DECLARE @sRes  VARCHAR(8)
  DECLARE @iTmp  INT
  DECLARE @iCount TINYINT

  SELECT @sRes = '', @iCount = 0
  WHILE(@iCount<4)
  BEGIN
    SET @iTmp = dbo.MD5_RShift(@iValue,@iCount*8) & 0x000000FF
    SET @sRes = @sRes + CASE @iTmp / 16 WHEN 0 THEN '0'
                      WHEN 1 THEN '1'
                      WHEN 2 THEN '2'

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]  下一页

  • 上一篇文章: 没有了

  • 下一篇文章: MD5算法研究
  • 发表评论】【告诉好友】【打印此文】【关闭窗口
     最新5篇热点文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 通过ASP记录进行分页[20012]

  • ASP开发准则[11932]

  • ASP组件指南[11943]

  • ASP指南[11967]

  •  
     最新5篇推荐文章
  • Knoppix 4.0.2 免硬盘免安…[15797]

  • 如何让Win 2003系统更加安…[13301]

  • Nero超刻简明教程[34139]

  • PS商业实战-来杯茶,行吗?…[7255]

  • ASP深度揭密(下)[12554]

  •  
     相 关 文 章
  • MD5算法研究[12631]


  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
        没有任何评论
    设为首页 | 加入收藏 | 关于我们 | 联系我们 | 友情链接 | 版权声明 | 管理登录
    Copyright © 2000-2022 Yicong.com.All Rights Reserved.
    亿聪 版权所有 E-mail: