Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

MD5 Expand / Collapse
Author
Message
Posted Friday, October 2, 2009 11:13 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 6, 2012 1:17 PM
Points: 24, Visits: 76
Comments posted to this topic are about the item MD5
Post #797101
Posted Wednesday, October 14, 2009 10:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 19, 2010 9:51 AM
Points: 1, Visits: 11
So how do you decrypt it?

Post #802892
Posted Wednesday, October 14, 2009 10:11 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 6, 2012 1:17 PM
Points: 24, Visits: 76
MD5 is a 'one way' algorithm. you can't decrypt it.
is very usefull to encrypt passwords, or data that you don't need to read directly.
for instance, if i store a md5 string of my password, the system have to compare two md5 strings (password_stored vs MD5(password_wrote)) to verify if my password is correct and letme log in.

greets...
Post #802907
Posted Tuesday, November 3, 2009 4:09 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 7:51 AM
Points: 20, Visits: 158
You must not use CAST(... AS NVARCHAR(32)), that would remove the 2 last characters

-- with SqlServer 2005
DECLARE @md5 VARCHAR(32)
DECLARE @string varchar(10)
SET @string = 'Davolio'
SELECT
HashBytes('MD5',@string ),
master.dbo.fn_varbintohexstr(HashBytes('MD5',@string )),
SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5',@string )),3,32 ),
SUBSTRING(CAST(master.dbo.fn_varbintohexstr(HashBytes('MD5',@string )) AS NVARCHAR(32)),3,32 )

Post #812853
Posted Tuesday, November 3, 2009 5:19 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 6, 2012 1:17 PM
Points: 24, Visits: 76
You are totally right...
typin' mistake...

the 'CAST' is to a NVARCHAR(MAX)

I tried a lot whitout that CAST and it returned another 'md5' string... i figure that the problem is in the asigment '@md5 = ...'

the sql corrected would be...

CREATE FUNCTION [dbo].[fn_MD5]
(
@string AS VARCHAR(MAX),
@chars AS INT
)
RETURNS NVARCHAR(32)
AS
BEGIN
-- Declare the return variable here
DECLARE @md5 NVARCHAR(32)

SELECT @md5 = SUBSTRING(CAST(master.dbo.fn_varbintohexstr(HashBytes('MD5',@string )) AS NVARCHAR(MAX)),3,@chars )

-- Return the result of the function
RETURN @md5
END
Post #812862
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse