February 1, 2012 at 12:11 pm
Following VB-code transforms string "123456" to "e10adc3949ba59abbe56e057f20f883e". Does anyone have any idea of how to do the same in TSQL??
--------------------
Dim txt As String = "123456"
Dim md5serv As MD5 = MD5CryptoServiceProvider.Create()
Dim strbld As New StringBuilder()
Dim ascenc As New ASCIIEncoding()
' convert string into array of bytes
Dim buffer As Byte() = ascenc.GetBytes(txt)
' Compute the hash for the string
Dim hash As Byte() = md5serv.ComputeHash(buffer)
For Each b As Byte In hash
strbld.Append(b.ToString("x2"))
Next
MsgBox(strbld.ToString()) 'Result = e10adc3949ba59abbe56e057f20f883e
February 1, 2012 at 12:21 pm
declare @val varbinary(max)
SELECT @val = HashBytes('MD5','123456')
print @val
--0xE10ADC3949BA59ABBE56E057F20F883E
SELECT
CASE
WHEN @val = HashBytes('MD5','123456')
THEN 'True'
ELSE 'FALSE'
END
Lowell
February 2, 2012 at 1:44 am
Thanks 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply