Friday, 20 April 2012

How To MD5 in SQL Server / MSSQL

If you need to MD5 a string in MSSQL then use the HASHBYTES function. You can also use other formats too, such as SHA and SHA1. It's as simple as:

PRINT HASHBYTES('MD5', 'MY_STRING')


If you want to return back a string rather than the varbinary HASHBYTES does return, then try the following:


PRINT SUBSTRING(master.dbo.fn_varbintohexstr( HASHBYTES ('MD5', ' MY_STRING ')), 3, 32)

No comments:

Post a Comment