Link to home
Start Free TrialLog in
Avatar of gplana
gplanaFlag for Spain

asked on

Function to encode MD5 in SQL-Server 2012

Hi.

I have created this function to get the MD5 code of a text:

FUNCTION [dbo].[fn_md5] (@data_a_codificar varchar) 
RETURNS CHAR(32) AS
BEGIN
  RETURN convert(varchar,hashbytes('MD5',@data_a_codificar),2)
END

Open in new window


Then I execute these two sentences:

select dbo.fn_md5('Hello');

select convert(char,hashbytes('MD5','Hello'),2)

Open in new window


Why aren't they returning the same values?
ASKER CERTIFIED SOLUTION
Avatar of Johny Bravo
Johny Bravo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gplana

ASKER

Thanks, but still different values. Here is the result of the two selects:

1A8E9B7EA00C8125B37DC3F231564C72
8B1A9953C4611296A827ABF8C47804D7
Avatar of gplana

ASKER

I have mispelled your solution. It works fine.

Thank you.