MySQL MS-SQL 中是否有与 SHA1() 等效的函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/184456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:11:13  来源:igfitidea点击:

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

sqlmysqlsha1tsqlsql-server

提问by GEOCHET

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.

将几个存储过程从 MySQL 转换为 Microsoft SQL 服务器。一切都很顺利,除了一个程序使用了 MySQLSHA1()函数。我似乎无法在 MS-SQL 中找到与此等效的内容。

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

有没有人知道SHA1()MS-SQL 上的有效等效项?

回答by Joel Coehoorn

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

SQL Server 2005 及更高版本具有HashBytes()函数。

回答by Peter

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.

如果您想获得与 MySQL 完全相同的 SHA1 哈希值(即作为 varchar),您可以将 HashBytes 与 sys.fn_varbintohexsubstring 结合使用。例如

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.htmlfor more details.

有关更多详细信息,请参阅http://accessrichard.blogspot.co.nz/2010/12/sql-server-and-net-equivalent-to-php.html

回答by LeppyR64

From google groups - A Possibility

来自 google 群组 -一种可能性

回答by James

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

您可能还想查看http://www.stev.org/post/2011/01/30/MS-SQL-SHASum-Support.aspx,您应该能够对其进行修改以生成您想要的任何内容。尽管可能需要一些 c# 编码。

回答by theraccoonbear

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

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