SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


MD5


Author
Message
Caesar2
Caesar2
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 76
Comments posted to this topic are about the item MD5
jbinnig
jbinnig
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 12
So how do you decrypt it?
Caesar2
Caesar2
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 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...
phamminh
phamminh
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 197
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 )
Caesar2
Caesar2
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 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
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21996 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search