Sqlite connection string with encrypted password

☆樱花仙子☆ 提交于 2021-02-08 11:57:26

问题


I have an encrypted database using "SQLite Cipher". When I try to connect to the database using Connection string the following error message appears:

'SQL logic error Cannot use "Password" connection string property: library was not built with encryption support.'

Code With Error

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


回答1:


Change System.data.sqlite by this package Link

To set a password to an unprotected database:

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

To open a password-protected database:

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

or

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

To remove password from a password-protected database:

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

Note: The open source database manager SQLiteStudio is able to open files which were password-protected that way, as long as you choose System.Data.SQLite instead of Sqlite 3 as your database type. (Requires v 3.1.1, the current version).




回答2:


Source of the issue

I assume that the actual reason for this error is the the lack of support in "legacy CryptoAPI" since System.Data.SQLite version ~1.0.113.1.

It was done in the following commit: https://system.data.sqlite.org/index.html/info/1dd56c9fd59a10fd

What can we do?

  1. Manually Use the last NuGet version with CryptoAPI support - 1.0.112.2.

    Notice - It must be done manually - either by editing PackageReference in csproj or by editing config.packages. the reason is that older versions are unlisted (!) from the NuGet feed:

  2. Buy perpetual source code license for SQLite Encryption Extension (SEE) which costs one time fee of 2000$ (as of Feb 2020) - purchase link

  3. Use SQLCipher - SQLCipher is an SQLite extension that provides 256 bit AES encryption of database files - GitHub source (haven't tested it myself!)

Data Sources

  • https://system.data.sqlite.org/index.html/tktview?name=9c330a3e03
  • https://stackoverflow.com/a/64392325/426315


来源:https://stackoverflow.com/questions/62616861/sqlite-connection-string-with-encrypted-password

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