SQL Server中的MD5实现方法
时间:2010-09-05 来源:ggf6318
--SQL Server中的MD5实现方法
/*****************************************************************************
* 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
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_AddUnsigned(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
/*****************************************************************************
* Name: MD5_GG
* Description: MD5_GG
*****************************************************************************/
CREATE FUNCTION dbo.MD5_GG(
@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_G(@b, @c, @d), @x), @ac))
SET @a = dbo.MD5_RotateLeft(@a, @s)
SET @a = dbo.MD5_AddUnsigned(@a, @b)
RETURN(@a)
END
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
GO
/*****************************************************************************
* Name: MD5_I
* Description: MD5_I
*****************************************************************************/
CREATE FUNCTION dbo.MD5_I(
@x INT
,@y INT
,@z INT
)
RETURNS INT
WITH ENCRYPTION
AS
BEGIN
RETURN(@y ^ (@x | (