/ ************************************************** *************************** * Name: T-SQL MD5 algorithm implementation * Author: rambo qian * create date: 2003-04- 10 * Last Modified by: Rambo Qian * Last Update Date: 2003-04-16 * Version: v1.0.00 ************************************ *********************************************************** * / GO
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [MD5_M_ONBITS]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [MD5_M_ONBITS] GO / ********************************************************************** ******************************** * NAME: MD5_M_ONBITS * DESCRIPTION: constant group ******** *********************************************************** **************************** / CREATE FUNCTION DBO.MD5_M_ONBITS (@i tinyint) returns int with encryption as begin declare @IRES INT SELECT @IRES = CASE @
i WHEN 0 THEN 1 - 00000000000000000000000000000001 WHEN 1 THEN 3 - 00000000000000000000000000000011 WHEN 2 THEN 7 - 00000000000000000000000000000111 WHEN 3 THEN 15 - 00000000000000000000000000001111 WHEN 4 THEN 31 - 00000000000000000000000000011111 WHEN 5 THEN 63 - 00000000000000000000000000111111 WHEN 6 THEN 127 - 00000000000000000000000001111111 WHEN 7 THEN 255 - 00000000000000000000000011111111 WHEN 8 THEN 511 - 00000000000000000000000111111111 WHEN 9 THEN 1023 - 00000000000000000000001111111111 WHEN 10 THEN 2047 - 00000000000000000000011111111111 WHEN 11 THEN 4095 - 00000000000000000000111111111111 WHEN 12 THEN 8191 - 00000000000000000001111111111111 WHEN 13 THEN 16383 - 00000000000000000011111111111111 WHEN 14 death 111 WHEN 16 THEN 131071 - 00000000000000011111111111111111 WHEN 17 THEN 262143 - 00000000000000111111111111111111 WHEN 18 THEN 524287 - 00000000000001111111111111111111 WHEN 19 THEN 1048575 - 00000000000011111111111111111111 WHEN 20 THEN 2097151 - 00000000000111111111111111111111 WHEN 21 THEN 4194303 - 00000000001111111111111111111111 WHEN 22 THEN 8388607 - 00000000011111111111111111111111 WHEN 23 THEN 16777215 - 00000000111111111111111111111111 WHEN 24 THEN 33554431 - 00000001111111111111111111111111 WHEN 25 THEN 67108863 - 00000011111111111111111111111111 WHEN 26 THEN 134217727 - 00000111111111111111111111111111 WHEN 27 THEN 26843545
5 - 00001111111111111111111111111111 WHEN 28 THEN 536870911 - 00011111111111111111111111111111 WHEN 29 THEN 1073741823 - 00111111111111111111111111111111 WHEN 30 THEN 2147483647 - 01111111111111111111111111111111 ELSE 0 END RETURN (@iRes) END GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID (N ' [MD5_M_2POWER] ') and xtype in (n'fn', n'if ', n't')) DROP FUNCTION [DBO]. [MD5_M_2Power] Go / ********** *********************************************************** **************** * Name: MD5_M_2Power * Description: constant group ********************************* *********************************************************** *** / create function dbo.md5_m_2power (@i tinyint) returns int with encryption as begin declare @IRES int search @IRES = CASE @
i WHEN 0 THEN 1 - 00000000000000000000000000000001 WHEN 1 THEN 2 - 00000000000000000000000000000010 WHEN 2 THEN 4 - 00000000000000000000000000000100 WHEN 3 THEN 8 - 00000000000000000000000000001000 WHEN 4 THEN 16 - 00000000000000000000000000010000 WHEN 5 THEN 32 - 00000000000000000000000000100000 WHEN 6 THEN 64 - 00000000000000000000000001000000 WHEN 7 THEN 128 - 00000000000000000000000010000000 WHEN 8 THEN 256 - 00000000000000000000000100000000 WHEN 9 THEN 512 - 00000000000000000000001000000000 WHEN 10 THEN 1024 - 00000000000000000000010000000000 WHEN 11 THEN 2048 - 00000000000000000000100000000000 WHEN 12 THEN 4096 - 00000000000000000001000000000000 WHEN 13 THEN 8192 - 00000000000000000010000000000000 WHEN 14 death 16384- 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 WHEN 16 THEN 65536 - 00000000000000010000000000000000 WHEN 17 THEN 131072 - 00000000000000100000000000000000 WHEN 18 THEN 262144 - 00000000000001000000000000000000 WHEN 19 THEN 524288 - 00000000000010000000000000000000 WHEN 20 THEN 1048576 - 00000000000100000000000000000000 WHEN 21 THEN 2097152 - 00000000001000000000000000000000 WHEN 22 THEN 4194304 - 00000000010000000000000000000000 WHEN 23 THEN 8388608 - 00000000100000000000000000000000 WHEN 24 THEN 16777216 - 00000001000000000000000000000000 WHEN 25 THEN 33554432 - 00000010000000000000000000000000 WHEN 26 THEN 67108864 - 00000100000000000000000000000000 WHEN 27 THEN 134217728 -
- 00001000000000000000000000000000 WHEN 28 THEN 268435456 - 00010000000000000000000000000000 WHEN 29 THEN 536870912 - 00100000000000000000000000000000 WHEN 30 THEN 1073741824 - 01000000000000000000000000000000 ELSE 0 END RETURN (@iRes) END GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID (N '[dbo ]. [Md5_lshift] ') and xtype in (N'FN', N'IF ', N'TF')) DROP FUNCTION [DBO]. [MD5_LSHIFT] GO / ************ *********************************************************** ************** * Name: MD5_LSHIFT * DESCRIPTION: MD5_LSHIFT ************************************ *********************************************************** / CREATE FUNCTION dbo.MD5_LShift (@iValue INT, @ iShiftBits TINYINT) RETURNS INT WITH ENCRYPTION AS BEGIN DECLARE @iRes BIGINT SET @iRes = CAST (@iValue AS BINARY (8)) SET @iRes = @iRes * dbo.MD5_m_2Power ( @ishiftbits) Return (Cast (@ires & 0x00000000FFFFFFFF AS BINARY (4)) End GO
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_rshift]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [MD5_RSHIFT] GO / ************************************************************ ******************************** * Name: MD5_RSHIFT * DESCRIPTION: MD5_RSHIFT ********* *********************************************************** ***************** / CREATE FUNCTION DBO.MD5_RSHIFT (@IValue int, @ iShiftBits tinyint) Returns int with encryption as begin declare @IRES bigint set @IRES = CAST (@ iValue AS BINARY (8)) SET @iRes = @iRes / dbo.MD5_m_2Power (@iShiftBits) RETURN (CAST (@iRes & 0x00000000FFFFFFFF AS BINARY (4))) END GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID (N '[dbo]. [Md5_rotateleft]') and xtype in (n'fn ', n'if', n't ')) DROP FUNCTION [DBO]. [MD5_ROTATELEFT] GO / ******* *********************************************************** ******************* * Name: MD5_ROTATELEFT * DESCRIPTION: MD5_ROTATELEFT *********************** ***************************** ************************ / CREATE FUNCTION DBO.MD5_ROTATELEFT (@iValue int, @ iShiftBits Tinyint) Returns int with encwicking as begin Return (dbo.md5_lshift (@IValue, @ishiftbits) | dbo.md5_rshift (@IValue, (32 - @ishiftbits)) End GO
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_addunsigned]') And xtype in (n'fn ', n'if ", n't')) DROP FUNCTION [DBO] [M /] GO / *********************************************************** ******************************** * NAME: MD5_ADDUNSIGNED * DESCRIPTION: MD5_ADDUNSIGNED ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_ADDUNSIGNED (@ix int, @ IY int) Returns int with encryption as begin declare @IRES bigint set @ires = cast (CAST) (@iX AS BINARY (8)) AS BIGINT) CAST (CAST (@iY AS BINARY (8)) AS BIGINT) RETURN (CAST (@iRes & 0x00000000FFFFFFFF AS BINARY (4))) END GOIF EXISTS (SELECT * FROM DBO.SYSOBJECTS WHERE ID = Object_ID (N '[DBO]. [MD5_f]') and xtype in (N'FN ', N'IF', N'TF ')) DROP FUNCTION [DBO]. [MD5_F] GO / *********************************************************** ************************** * NAME: MD5_F * Description: MD5_F ***************** *********************************************************** ************ / Create function dbo.md5_f (@x int, @ y int, @ z int) Returns int with encryption as begin Return ((@ x & @y) | (~ @ x) & @z)) End Go
IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_g]') and xtype in (n'fn ', n'if', n't ')) DROP FUNCTION [DBO] [M ******************************************************** ********************************* * Name: MD5_G * Description: MD5_G ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_G (@x int, @ y int, @ z int) Returns int with encryption as begin Return ((@ x & @ z) | (@Y & (~ @ z))) End Goif Exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [md5_h]') and xtype in (n'fn ', n 'IF', N'TF ')) Drop Function [DBO]. [MD5_H] GO / **************************************** ********************************************** * Name : MD5_H * Description: MD5_H *************************************************************** ******************************************* / CREATE FUNCTION DBO.MD5_H (@X INT, @ Y Int, @ z INT) RETURNS INT with Encryption As Begin Return (@X ^ @Y ^ @z) End Go
IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_i]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [M / *] GO / ************************************************** ******************************** * Name: MD5_i * description: MD5_i ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_I (@X INT, @ y int, @ z int) returins int with encwtion as begin Return (@y ^ (@ X | (~ @ z))) End GO
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_ff]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [MD5_FF] GO / ******************************************************************************************************************************************************************************************************************************************************************************* ******************************** * NAME: MD5_FF * Description: MD5_FF ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_FF (@a int, @ b int, @ c int, @ D int, @ x int, @ s int, @ AC INT) RETURNS INT with Encryption As Begin Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_addunsigned (dbo.md5_f (@B, @C, @D), @x), @ac)) Set @a = dbo.md5_rotateleft (@a, @S) set @a = dbo.md5_addunsigned (@A, @B) Return (@a) end goif exists (select * from dbo.sysObjects where id = Object_id (n ' [MD5_GG] ') And xtype in (N'FN', N'IF ', N'TF')) Drop function [dbo]. [MD5_GG] GO / ********* *********************************************************** **************** * NAME: MD5_GG * Description: MD5_GG ************************************** ******* ***************************************************************** / CREATE FUNCTION DBO. MD5_GG (@a int, @ b int, @ c int, @ D int, @ X int, @ s int (dbo.md5_addunsigned (dbo.md5_g (@B, @C, @D), @X), @ac) set @a = dbo.md5_rotateleft (@a, @S) set @a = dbo.md5_addunsigned (@A A, @B) Return (@A) end Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_hh]') and xtype in (N'FN ', N'IF', N'TF ')) DROP FUNCTION [DBO] [MD5_HH] GO / ************************************************************ ******************************** * NAME: MD5_HH * DESCRIPTION: MD5_HH ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_HH (@a int, @ b Int, @ c int, @ D int, @ x int, @ s int, @ AC INT) RETURNS INT with Encryption As Begin Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_ddunsigned (dbo.md5_h (@B, @c, @D), @X), @ac)) Set @a = dbo.md5_rotateleft (@a, @S) set @a = dbo.md5_addunsigned (@a, @B) Return (@A) end Go
IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_ii]') and xtype in (N'FN ', N'IF', N'TF ')) DROP FUNCTION [DBO] [MD5_II] go / ************************************************************ ******************************** * Name: MD5_II * Description: MD5_II ********* *********************************************************** ****************** / CREATE FUNCTION DBO.MD5_II (@a Int, @ b Int, @ c int, @ D int, @ x int, @ s int, @ AC INT) RETURNS INT with Encryption As Begin Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_addunsigned (dbo.md5_i (@B, @c, @D), @X), @ac) Set @a = dbo.md5_rotateleft (@a, @S) set @a = dbo.md5_addunsigned (@A, @B) Return (@a) end goif exists (select * from dbo.sysObjects where id = Object_id (n ' [MD5_CONVERTTOORDARRAY] ') And xtype in (N'FN', N'IF ', N'TF')) DROP FUNCTION [DBO]. [MD5_CONVERTTOWORDARRAY] GO / ********** *********************************************************** **************** * NAME: MD5_CONVERTTOWORDARRAY * DESC Ription: md5_convertToWordArray ********************************************************** *************************************** / CREATE FUNCTION DBO.MD5_CONVERTTOWORDARRAY (@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 ENDSELECT @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 (@SORIGMESS, @ iposofmess 1, 1)), @ iposofword * 8) Where [id] = @icountofword set @iposofmess = @iposofmess 1 end select @icount @ @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 (@ ilnofmess, 3) Where [id] = @iwordArraylen - 2 Update @twordArray set [word] = [word] | dbo.md5_rshift (@ ionofmess, 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] [M /] 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' When 3 Then '3' When 4 Then '4' When 5 Then '5' When 6 Then '6' When 7 Then '7' When 8 THEN '8' When 9 Then '9' When 10 Then 'a' When 11 Then 'b' When 12 TEN 'C' WHEN 13 TEN 'D' WHEN 14 THEN 'E' WHEN 15 TEN 'F' ELSE 'END Case @itmp% 16 when 0 Then '0' When 1 Then '1' When 2 Then '2' When 3 TEN '3' WHEN 4 THEN '4' When 5 TEN '5' WHEN 6 '6' WHEN 7 THEN '7' WHEN 8 TEN '8' WHEN 9 TEN '9' WHEN 10 TEN 'A' WHEN 11 THEN 'B' WHEN 12 TEN 'C' WHEN 13 Then 'D' When 14 Then 'e' When 15 Then '
F 'Else' End Set @icount = @icount 1 End Return (@SRES) End Goif Exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5]') and xtype in. N'FN ', N'IF', N'TF ')) Drop Function [DBO]. [MD5] GO / ********************************** *********************************************************** **** * Name: MD5 * Description: md5 ************************************************ ************************************************ / CREATE FUNCTION DBO.MD5 (@sorigmess nvarchar) 4000) Returns Char (32) with encryption as begin - ==================================== DECLARE @ S11 TINYINT DECLARE @ S12 TINYINT DECLARE @ S13 TINYINT DECLARE @ S14 TINYINT DECLARE @ S21 TINYINT DECLARE @ S22 TINYINT DECLARE @ S23 TINYINT DECLARE @ S24 TINYINT DECLARE @ S31 TINYINT DECLARE @ S32 TINYINT DECLARE @ S33 TINYINT DECLARE @ S34 TINYINT DECLARE @ S41 Tinyint Declare @ s42 tinyint declare @ s43 tinyint declare @ s44 tinyint
SELECT @ S11 = 7, @ S12 = 12, @ S13 = 17, @ S14 = 22 SELECT @ S21 = 5, @ S22 = 9, @ S23 = 14, @ S24 = 20 Select @ S31 = 4, @ S32 = 11 , @ S33 = 16, @ S34 = 23 SELECT @ S41 = 6, @ S42 = 10, @ S43 = 15, @ S44 = 21 - ================== ================== Declare @a int declare @B int declare @c int decLare @BB int declare @cc int declare @dd Intselect @A = 0x67452301, @ b = 0xEfcdab89, @ c = 0x98badcfe, @ D = 0x10325476 - ============================= ======= Declare @sres varchar (32) set @sres = '' declare @iwordArraylen int declare @iwordArraycount Int
Declare @ttmp table ([ID] int, [word] int) INSERT INTO @ttmp select * from dbo.md5_converttoWordArray (@sorigmess) select @ iWordArrayCount = 0, @iwordArraylen = count (*) from @ttmp
While (@iwordArraycount <@iwordaraylen) begin select @aa = @a, @BB = @B, @cc = @c, @dd = @d
Select @a = dbo.md5_ff (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordaraycount 0), @ S11, 0XD76AA478) SELECT @d = dbo. MD5_FF (@D, @A, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 1), @ S12, 0xE8C7B756) SELECT @c = dbo.md5_ff (@c, @ D, @a, @B, (select [word] from @ttmp where [id] = @iwordaraycount 2), @ S13, 0x242070dB) SELECT @B = dbo.md5_ff (@B, @c, @d, @ A, (Select [word] from @ttmp where [id] = @iwordArraycount 3), @ S14, 0xc1bdceee) select @a = dbo.md5_ff (@A, @B, @c, @d, (Select [Word ] From @ttmp where [id] = @iwordArraycount 4), @ S11, 0xf57c0faf) SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [ ID] = @iWordArraycount 5), @ S12, 0x4787C62A) SELECT @c = dbo.md5_ff (@C, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 6), @ S13, 0xA8304613) SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S14, 0xFD469501) SELECT @A = DBO. MD5_FF (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S11, 0x698098d8) SELECT @D = dbo.md5_ff (@d, @ A, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S12, 0x8B44F7AF) SELECT @c = dbo.md5_ff (@c, @d, @a, @
B, (Select [word] from @ttmp where [id] = @iwordArraycount 10), @ S13, 0xfffff5bb1) select @B = dbo.md5_ff (@B, @c, @d, @a, (select [word ] From @ttmp where [id] = @iwordArraycount 11), @ S14, 0x895cd7be) SELECT @A = dbo.md5_ff (@A, @B, @c, @d, (select [word] from @ttmp where [ ID] = @iWordArrayCount 12), @ S11, 0x6b901122) SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 13), @ S12, 0xFD987193) SELECT @C = dbo.md5_ff (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ S13, 0xA679438E) SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S14, 0x49b40821)
SELECT @a = dbo.md5_gg (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordaraycount 1), @ S21, 0xF61e2562) SELECT @d = dbo. MD5_GG (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 6), @ S22, 0xc040b340) SELECT @c = dbo.md5_gg (@c, @ D, @a, @B, (Select [word] from @ttmp where [id] = @iwordArraycount 11), @ S23, 0x265e5a51) select @B = dbo.md5_gg (@B, @c, @d, @ A, (Select [Word] from @ttmp where [id] = @iwordArraycount 0), @ S24, 0xE9B6C7AA) SELECT @a = dbo.md5_gg (@A, @B, @c, @d, (Select [Word ] From @ttmp where [id] = @iwordArraycount 5), @ S21, 0xD62F105D) SELECT @d = dbo.md5_gg (@D, @A, @B, @c, (select [word] from @ttmp where [ ID] @ iWordArraycount 10), @ S22, 0X2441453) SELECT @c = dbo.md5_gg (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S23, 0xD8A1E681) SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 4), @ S24, 0xE7D3FBC8) SELECT @A = DB O.MD5_GG (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S21, 0x21e1cde6) SELECT @d = dbo.md5_gg (@d) , @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ S22, 0XC33707D6) SELECT @c = dbo.md5_gg (@c, @d, @a , @
B, (Select [word] from @ttmp where [id] = @iwordaraycount 3), @ S23, 0xF4D50D87) SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (Select [Word ] From @ttmp where [id] = @iwordArraycount 8), @ S24, 0x455A14ED) SELECT @a = dbo.md5_gg (@A, @B, @c, @d, (Select [Word] from @ttmp where [ ID] = @iWordArraycount 13), @ S21, 0xA9E3E905) SELECT @D = dbo.md5_gg (@D, @A, @B, @c, (select [word] from @ttmp where [id] = @iWordArraycount 2), @ S22, 0xfcefa3f8) SELECT @c = dbo.md5_gg (@c, @D, @a, @B, (select [word] from @tmp where [id] = @iwordArraycount 7), @ S23, 0x676f02d9) SELECT @B = dbo.md5_gg (@B, @C, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 12), @ S24, 0x8D2A4C8A)
Select @a = dbo.md5_hh (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordaraycount 5), @ S31, 0xffa3942) SELECT @d = dbo. MD5_HH (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S32, 0x8771f681) SELECT @c = dbo.md5_hh (@c, @ D, @a, @B, (Select [word] from @ttmp where [id] = @iwordArraycount 11), @ S33, 0x6d9d6122) SELECT @B = dbo.md5_hh (@B, @c, @d, @ A, (Select [word] from @ttmp where [id] = @iwordaraycount 14), @ S34, 0xFDE5380C) SELECT @a = dbo.md5_hh (@a, @B, @c, @d, (select [word ] From @ttmp where [id] = @iWordArraycount 1), @ S31, 0xA4beea44) SELECT @D = dbo.md5_hh (@D, @a, @B, @c, (select [word] from @ttmp where [ ID] @ iWordArraycount 4), @ s32, 0x4bdecfa9) SELECT @c = dbo.md5_hh (@c, @d, @a, @B, (select [word] from @ttmp wherecount 7), @ s33, 0xf6bb4b60) SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordaraycount 10), @ S34, 0xBebfbc70) SELECT @A = D Bo.md5_hh (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 13), @ S31, 0x289b7ec6) SELECT @d = dbo.md5_hh (@d) , @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S32, 0xEAA127FA) SELECT @c = dbo.md5_hh (@c, @d, @a , @
B, (Select [word] from @ttmp where [id] = @iwordArraycount 3), @ S33, 0xD4ef3085) SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (Select [Word ] From @ttmp where [id] = @iwordArraycount 6), @ S34, 0x4881D05) SELECT @A = dbo.md5_hh (@A, @B, @c, @d, (select [word] from @ttmp where [ ID] = @ iWordArraycount 9), @ S31, 0xD9D4D039) SELECT @D = dbo.md5_hh (@D, @a, @B, @c, (select [word] from @ttmp wherecount 12), @ S32, 0xE6DB99E5) SELECT @c = dbo.md5_hh (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S33, 0x1fa27cf8) SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S34, 0xc4ac5665)
Select @a = dbo.md5_ii (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S41, 0xF4292244) Select @d = dbo. MD5_II (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S42, 0x432AFF97) SELECT @c = dbo.md5_ii (@c, @ D, @a, @B, (select [word] from @ttmp where [id] = @iwordaraycount 14), @ S43, 0xAb9423a7) SELECT @B = dbo.md5_ii (@B, @c, @d, @ A, (Select [word] from @ttmp where [id] = @iwordaraycount 5), @ S44, 0xFC93A039) SELECT @A = dbo.md5_ii (@A, @B, @c, @d, (Select [Word ] From @ttmp where [id] = @iwordArraycount 12), @ S41, 0x65559c3) SELECT @d = dbo.md5_ii (@D, @a, @B, @c, (select [word] from @ttmp where [ ID] @ iWordArraycount 3), @ s42, 0x8f0cc92) SELECT @c = dbo.md5_ii (@c, @d, @a, @B, (select [word] from @ttmp wherecount 10), @ S43, 0xffeff47d) SELECT @B = dbo.md5_ii (@B, @C, @d, @A, (select [word] from @ttmp where [id] = @iwordArraycount 1), @ S44, 0x85845dd1) SELECT @A = D Bo.md5_ii (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S41, 0x6fa87e4f) select @d = dbo.md5_ii (@D) , @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S42, 0xfe2ce6e0) SELECT @c = dbo.md5_ii (@c, @d, @a , @
B, (Select [word] from @ttmp where [id] = @iwordArraycount 6), @ S43, 0xA3014314) SELECT @B = dbo.md5_ii (@B, @c, @d, @a, (Select [Word ] From @ttmp where [id] = @iwordArraycount 13), @ s44, 0x4e0811a1) select @a = dbo.md5_ii (@a, @B, @c, @d, (select [word] from @ttmp where [ ID] = @iWordArraycount 4), @ s41, 0xf7537e82) SELECT @D = dbo.md5_ii (@D, @a, @B, @c, (select [word] from @ttmp wherecount 11), @ s42, 0xbd3af235) SELECT @c = dbo.md5_ii (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S43, 0x2ad7d2bb) select @B = dbo.md5_ii (@B, @C, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S44, 0xEB86D391) set @a = DBO.MD5_ADDUNSIGNED (@A, @AA) set @B = dbo.md5_addunsigned (@B, @BB) set @c = dbo.md5_addunsigned (@c, @cc) set @d = dbo.md5_addunsigned (@d, @ DD)
Set @iwordArraycount = @iwordArrayCount 16 END
Set @SRES = dbo.md5_wordtohex (@a) dbo.md5_wordtohex (@B) DBO.MD5_WORDTOHEX (@c) dbo.md5_wordtohex (@d) set @SRES = Lower (@sres) Return (@sres) End Go
--Test set nocount on select dbo.md5 ('') AS 'MD5 (' '') 'union select' D41D8CD98F00B204E9800998ECF8427E '
SELECT DBO.MD5 ('A') AS 'MD5 (' 'a') 'union select' 0cc175b9c0f1b6a831c399e269772661 '
select dbo.MD5 ( 'abc') as 'MD5 (' 'abc' ')' union select '900150983cd24fb0d6963f7d28e17f72'select dbo.MD5 (' message digest ') as' MD5 ( '' message digest '') 'union select' F96B697D7CB7938D525A2F31AAF161D0 '
Select dbo.md5 ('AbcdefghijklmnopqrStuvwxyz') AS 'MD5 (' 'AbcdefghijklmnopqrStuvwxyz') 'Union Select' C3FCD3D76192E4007DFB496CCA67E13B '
select dbo.MD5 ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') as 'MD5 (' 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ')' union select 'd174ab98d277d9f5a5611c2c9f419d9f'
select dbo.MD5 ( '12345678901234567890123456789012345678901234567890123456789012345678901234567890') as 'MD5 (' '12345678901234567890123456789012345678901234567890123456789012345678901234567890' ')' union select '57edf4a22be3c955ac49da2e2107b67a'
select dbo.MD5 ( 'I') as 'MD5 (' 'I' ')' union select 'a31d0f25367ebe046897f8a939ca4a9f' (Author: Rambo Qian)