Convert HashBytes to VarChar

前端 未结 7 784
南旧
南旧 2020-12-07 10:08

I want to get the MD5 Hash of a string value in SQL Server 2005. I do this with the following command:

SELECT HashBytes(\'MD5\', \'HelloWorld\')
7条回答
  •  清歌不尽
    2020-12-07 10:58

    Use master.dbo.fn_varbintohexsubstring(0, HashBytes('SHA1', @input), 1, 0) instead of master.dbo.fn_varbintohexstr and then substringing the result.

    In fact fn_varbintohexstr calls fn_varbintohexsubstring internally. The first argument of fn_varbintohexsubstring tells it to add 0xF as the prefix or not. fn_varbintohexstr calls fn_varbintohexsubstring with 1 as the first argument internaly.

    Because you don't need 0xF, call fn_varbintohexsubstring directly.

提交回复
热议问题