问题
I am handling a Unity project using SQLite. When I open an encrypted database, the following error message shows up:
EntryPointNotFoundException: sqlite3_key Mono.Data.Sqlite.SQLite3.SetPassword (System.Byte[] passwordBytes) Mono.Data.Sqlite.SqliteConnection.Open () SQLiteHandler.Start () (at Assets/Script/SQLiteHandler.cs:18)
Here is my connection code, neither putting the password into connection string nor using SetPassword work.
connString = string.Format("Data Source={0};Version=3;Password=testing123",Application.dataPath+"/demodb.db");
using (conn = new SqliteConnection (connString)) {
conn.Open ();
//do something
conn.Close ();
}
回答1:
Mono.Data.Sqlite does not support password protection, it does not include the two critical entry points sqlite3_key and sqlite3_rekey. So, better look for other extensions or libraries.
Here is a useful Unity package SqlCipher4Unity which fits well with password protection.
回答2:
You have to use SetPassword() when you create the Database initially (or at least before it is opened) - for example:
SQLiteConnection.CreateFile(DataPath + "/SomeDb.sqlite");
SQLiteConnection cnn = new SQLiteConnection("Data Source=" + DataPath + "/SomeDb.sqlite");
cnn.SetPassword("testing123!");
Then you can use the password in the connection string to access the database - for example:
var ConnectionString = "Data Source=" + DataPath + "/SomeDb.sqlite;Password=testing123!;";
Hopefully that will help you out.
来源:https://stackoverflow.com/questions/43921646/sqlite-cannot-open-database-with-password-encryption