Is there an equivalent to SHA1() in MS-SQL?

坚强是说给别人听的谎言 提交于 2019-12-12 09:28:34

问题


Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going well, except one procedure used the MySQL SHA1() function. I cannot seem to find an equivalent to this in MS-SQL.

Does anyone know a valid equivalent for SHA1() on MS-SQL?


回答1:


SQL Server 2005 and later has the HashBytes() function.




回答2:


If you want to get a SHA1 hash exactly as MySQL would generate it (i.e. as a varchar), you can combine HashBytes with sys.fn_varbintohexsubstring. E.g.

SELECT sys.fn_varbintohexsubstring(0, HashBytes('SHA1', 'password'), 1, 0)

See http://accessrichard.blogspot.co.nz/2010/12/sql-server-and-net-equivalent-to-php.html for more details.




回答3:


From google groups - A Possibility




回答4:


You may also want to check out http://www.stev.org/post/2011/01/30/MS-SQL-SHASum-Support.aspx you should be able to modify it to produce anything you want. Though some c# coding may be required.




回答5:


I don't believe there's native support, but you may want to check this out...

http://blogs.msdn.com/sqlcat/archive/2005/09/16/469257.aspx



来源:https://stackoverflow.com/questions/184456/is-there-an-equivalent-to-sha1-in-ms-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!