'Where is "SetPassword" or "ChangePassword" in SQLiteConnection class?

I'm just learning how to encrypt/decrypt SQLite database.
I found a way to encrypt, as in this post SQLite with encryption/password protection

This page's best answer said that we can use SEE,wxSQLite,SQLCipher,SQLiteCrypt, etc... to encrypt.

I can understand.

And, another answer said that we can use:

SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.open();

This page also says the same: Password Protect a SQLite DB. Is it possible?

However, SQLiteConnection doesn't have SetPassword nor ChangePassword methods. I'm very confused.

Where are SetPasword or ChangePassword?
Are these in SEE, wxSQLite,SQLCipher,SQLiteCrypt?

[Development environment]
VisualStudio2010 .NET Framework 4 Client Profile System.Data.SQLite.dll (https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki)

I downloaded zip from there, and I picked up "System.Data.SQLite.dll"



Solution 1:[1]

if you want to encrypt/decrypt SQLite database. there are some information for you

Please check the Specify the key section in the official documentation if you have other problem.

The method for encrypting and decrypting existing databases varies depending on which solution you're using. For example, you need to use the sqlcipher_export() function on SQLCipher. Check your solution's documentation for details.

You can use the SQLCipher API to finish your work:

  1. If you want to build a encrypting database, just set your connection string, like this:Data Source = encryptedName.db; Password=YourPassword

  2. if you want to change password in a encrypting database

    // you can use this in startup.cs
    using var changePasswordDb = new DBContext(
        new SqliteConnection(
                new SqliteConnectionStringBuilder()
                    {
                         DataSource = "encryptedName.db",
                         Mode = SqliteOpenMode.ReadWriteCreate,
                         Password = oldPassword
                    }.ToString()
            ));
    changePasswordDb.Database.ExecuteSqlRaw($"PRAGMA rekey = {newPassword}");
    
    // or use SqliteConnection
    var connection = new SqliteConnection("Data Source =encryptedName.db.db;Password=yourPassword");
    connection.Open();
    var command = connection.CreateCommand();
    command.CommandText = "PRAGMA rekey = " + newPassword;
    command.ExecuteNonQuery();  
    
  3. if you want to encrypt a plaintext SQLite database , SQLCipher is not support directly. so you can use sqlcipher_export() to get the goal. look this How to encrypt a plaintext SQLite database to use SQLCipher (and avoid “file is encrypted or is not a database” errors)

// Example
command.CommandText = "ATTACH DATABASE 'encryptedName.db' AS encrypted KEY 'YourNewPassword';SELECT sqlcipher_export('encrypted');DETACH DATABASE encryptedName;";
  1. if you have some Performance Issue in Asp.net Core and Entity Framework Core , you need to check to these
  1. if you have other Performance Issue , you can check this SQLCipher Performance Optimization

Solution 2:[2]

It seems that starting with System.Data.SQLite version 1.0.113.0, support for encryption via SetPassword() and ChangePassword() was removed. See my answer here for details: https://stackoverflow.com/a/72073407/8586332

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ci Ty Chen
Solution 2 scooter