【问题标题】:Sqlite connection string with encrypted password带有加密密码的 Sqlite 连接字符串
【发布时间】:2020-06-28 00:16:40
【问题描述】:

我有一个使用 “SQLite Cipher” 的加密数据库。当我尝试使用连接字符串连接到数据库时,会出现以下错误消息:

'SQL 逻辑错误无法使用“密码”连接字符串属性:库未构建加密支持。'

Imports System.Data.SQLite
Public Class frm_projects
    Dim dtset As New SQLiteConnection("Data Source=Setting.db;Password=m;")

    Private Sub frm_projects_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            If dtset.State = ConnectionState.Closed Then
                dtset.Open()

            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Warning")
        End Try
    End Sub
End Class

Image From DB Browser sqlite Cipher

【问题讨论】:

  • 是否允许我们在您创建连接的位置查看您的代码?
  • Dim dtset As New SQLiteConnection("Data Source=Setting.db;Password=m;") Try If dtset.State = ConnectionState.Closed Then dtset.Open() MsgBox("Connection Success!" , MsgBoxStyle.Information, "Informations") 'list_projects.Items.Add("ANa") End If Catch ex As Exception MsgBox("Failed to connect to SQLite Database", MsgBoxStyle.Information, "Warning") End Try
  • 检查您的连接字符串。 Data Source=Setting.db 是什么?这应该是数据库的路径。也许您的意思是:Dim dtset As New SQLiteConnection($"Data Source={My.Settings.db};Password=m;") 其中db 是您的应用程序设置中的字符串属性。

标签: .net vb.net sqlite sqlcipher


【解决方案1】:

问题来源

我认为此错误的实际原因是自 System.Data.SQLite 版本 ~1.0.113.1 以来“遗留 CryptoAPI”缺乏支持。

这是在以下提交中完成的: https://system.data.sqlite.org/index.html/info/1dd56c9fd59a10fd

我们能做什么?

  1. 手动使用支持 CryptoAPI 的最新 NuGet 版本 - 1.0.112.2

    注意 - 必须手动完成 - 通过在 csproj 中编辑 PackageReference 或编辑 config.packages。 原因是旧版本未从the NuGet feed 中列出(!):

  2. SQLite Encryption Extension (SEE) 购买永久源代码许可证,一次性费用为 2000 美元(截至 2021 年 2 月)-purchase link

  3. 使用SQLCipher - SQLCipher 是一个 SQLite 扩展,它提供数据库文件的 256 位 AES 加密 - GitHub source(我自己没有测试过!)

数据源

【讨论】:

    【解决方案2】:

    通过这个包Link更改System.data.sqlite

    为未受保护的数据库设置密码:

    Dim conn = New SQLite.SQLiteConnection(
        "Data Source=C:\yourFolder\yourDB.db3;Version=3;")
    conn.Open()
    conn.ChangePassword("password")
    conn.Close()
    

    打开受密码保护的数据库:

    Dim conn = New SQLite.SQLiteConnection(
        "Data Source=C:\yourFolder\yourDB.db3;Version=3;")
    conn.SetPassword("password")
    conn.Open()
    conn.Close()
    

    Dim conn = New SQLite.SQLiteConnection(
        "Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
    conn.Open()
    conn.Close()
    

    要从受密码保护的数据库中删除密码:

    Dim conn = New SQLite.SQLiteConnection(
        "Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
    conn.Open()
    conn.ChangePassword(String.Empty)
    conn.Close()
    

    注意:只要您选择 System.Data.SQLite 而不是 Sqlite 3 作为数据库类型,开源数据库管理器 SQLiteStudio 就能够打开受密码保护的文件。 (需要 v 3.1.1,当前版本)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      相关资源
      最近更新 更多