October 14, 2009 at 10:00 am
So how do you decrypt it?
October 14, 2009 at 10:11 am
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...
November 3, 2009 at 4:09 am
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 )
November 3, 2009 at 5:19 am
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
May 23, 2016 at 4:54 pm
Thanks for the script.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply