Generate MD5 hash string with T-SQL

后端 未结 9 1716
自闭症患者
自闭症患者 2020-12-02 08:52

Is there a way to generate MD5 Hash string of type varchar(32) without using fn_varbintohexstr

SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes(\'MD5\', \'em         


        
相关标签:
9条回答
  • 2020-12-02 09:09
    CONVERT(VARCHAR(32), HashBytes('MD5', 'email@dot.com'), 2)
    
    0 讨论(0)
  • 2020-12-02 09:11
    SELECT CONVERT(
          VARCHAR(32),
          HASHBYTES(
                       'MD5',
                       CAST(prescrip.IsExpressExamRX AS VARCHAR(250))
                       + CAST(prescrip.[Description] AS VARCHAR(250))
                   ),
          2
      ) MD5_Value;
    

    works for me.

    0 讨论(0)
  • 2020-12-02 09:16

    try this:

    select SUBSTRING(sys.fn_sqlvarbasetostr(HASHBYTES('MD5',  'email@dot.com' )),3,32) 
    
    0 讨论(0)
  • 2020-12-02 09:21

    None of the other answers worked for me. Note that SQL Server will give different results if you pass in a hard-coded string versus feed it from a column in your result set. Below is the magic that worked for me to give a perfect match between SQL Server and MySql

    select LOWER(CONVERT(VARCHAR(32), HashBytes('MD5', CONVERT(varchar, EmailAddress)), 2)) from ...
    
    0 讨论(0)
  • 2020-12-02 09:24

    Use HashBytes

    SELECT HashBytes('MD5', 'email@dot.com')
    

    That will give you 0xF53BD08920E5D25809DF2563EF9C52B6

    -

    SELECT CONVERT(NVARCHAR(32),HashBytes('MD5', 'email@dot.com'),2)
    

    That will give you F53BD08920E5D25809DF2563EF9C52B6

    0 讨论(0)
  • 2020-12-02 09:25

    Solution:

    SUBSTRING(sys.fn_sqlvarbasetostr(HASHBYTES('MD5','your text')),3,32)
    
    0 讨论(0)
提交回复
热议问题