SQLite 中的 SHA1 哈希:如何? [英] SHA1 hashing in SQLite: how?
问题描述
并行处理多个数据库,需要用散列密码初始化一些记录.在 MS SQL server
中,有一些方便的函数可以即时散列:
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'))
SQLite
有没有类似的功能?
如果不是,那是最简单的解决方法(例如从 SQL server
中选择并以某种方式将其插入到 SQLite
表中)?
If not, which is the easiest workaround (such as select from SQL server
and somehow insert it into SQLite
tables)?
首选散列算法是 SHA1
,密码存储在 BLOB
列中.
The preferred hashing algorithm is SHA1
and the passwords are stored in a BLOB
column.
更新:我在当前项目中使用 C# 语言.
Update: I use C# language in the current project.
推荐答案
SQLite3 中没有内置这样的函数.
There is no such function built into SQLite3.
但是你可以定义一个用户函数,例如使用 sqlite3_create_function
如果您使用的是 C 接口,并用它实现 SHA-1.(但如果您有一个可编程接口,也许您可以在 SQL 引擎之外对密码进行 SHA-1 处理.)
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.)
您也可以尝试查找/创建扩展并使用 load_extension
函数,但我没有这方面的经验.
You could also try to find / create an extension and load with the load_extension
function, but I don't have experience on that.
- 参见这个关于SQLiteFunction Simple Not Working的答案a> 了解如何在 C# 中使用
System.Data.SQLite
定义自定义函数. - 使用 System.Security.Cryptography.SHA1 计算 SHA-1 哈希值.
- 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.
这篇关于SQLite 中的 SHA1 哈希:如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!