SQLA1中的SHA1哈希:怎么样? [英] SHA1 hashing in SQLite: how?
问题描述
并行使用多个数据库,需要使用哈希密码初始化一些记录。在 MS SQL服务器
中有一些方便的功能可以实时哈希:
HashBytes('SHA1',CONVERT(nvarchar(32),N'admin'))
是否有类似的函数 SQLite
?
如果没有,这是最简单的解决方法(例如选择 SQL server
,并以某种方式将其插入 SQLite
表)?
首选散列算法是 SHA1
,密码存储在 BLOB
列中。 / p>
更新:我在当前项目中使用C#语言。
SQLite3中没有内置这样的函数。
但您可以定义一个用户函数。 sqlite3_create_function
如果您重新使用C接口,并实现SHA-1。 (但是如果你有一个可编程的接口,你可以只是SHA-1的SQL引擎之外的密码。)
你也可以尝试找到/创建扩展和加载 load_extension
函数
- 使用 System.Security.Cryptography.SHA1 计算SHA-1散列。 / li>
li>请参阅在 SQLiteFunction简单无法工作的答案 如何在C#中使用
System.Data.SQLite
定义自定义函数。 Working with several DBs in parallel and need to initialize some records with hashed passwords. In MS SQL server
there are handy functions that allow to hash on the fly:
HashBytes('SHA1', CONVERT(nvarchar(32), N'admin'))
Is there is a similar function with SQLite
?
If not, which is the easiest workaround (such as select from SQL server
and somehow insert it into SQLite
tables)?
The preferred hashing algorithm is SHA1
and the passwords are stored in a BLOB
column.
Update: I use C# language in the current project.
There is no such function built into SQLite3.
But you could define a user function e.g. with sqlite3_create_function
if you're using the C interface, and implement SHA-1 with that. (But if you're having a programmable interface perhaps you could just SHA-1 the password outside of the SQL engine.)
You could also try to find / create an extension and load with the load_extension
function, but I don't have experience on that.
Edit:
- See this answer on SQLiteFunction Simple Not Working for how to define a custom function with
System.Data.SQLite
in C#. - Use System.Security.Cryptography.SHA1 to compute the SHA-1 hash.
这篇关于SQLA1中的SHA1哈希:怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!