Bug 23837 - Exception thrown - System.EntryPointNotFoundException: sqlite3_key
Summary: Exception thrown - System.EntryPointNotFoundException: sqlite3_key
Status: RESOLVED ANSWERED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Data.Sqlite ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-10-15 08:31 UTC by wanda
Modified: 2018-03-13 16:19 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample (16.15 KB, application/zip)
2016-04-28 01:25 UTC, Cody Beyer (MSFT)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description wanda 2014-10-15 08:31:37 UTC
I am using visual studio and xamarin.android.
I am using Mono.Data.Sqlite
My goal is to create a sqlite db which is password protected.
I do not want to buy any encryption libraries like sqlcipher.
Code for creating sqliteconnection

var dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbFile);

try
            {
                var connString = "Data Source=" + dbPath + ";Password=Mypass;";
                conn = new SqliteConnection(connString);
                conn.Open();
                conn.Close();
            }
            catch
            {
                var connString = "Data Source=" + dbPath;
                conn = new SqliteConnection(connString);
                conn.SetPassword("Mypass");
                conn.Open();
                conn.Close();
            }

I tried SetPassword(string) and SetPassword(byte[]), same exception is thrown.


Exception thrown when call Open after calling SetPassword:

{System.EntryPointNotFoundException: sqlite3_key
  at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods:sqlite3_key (intptr,byte[],int)
  at Mono.Data.Sqlite.SQLite3.SetPassword (System.Byte[] passwordBytes) [0x00000] in <filename unknown>:0 
  at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in <filename unknown>:0 
  at User_Droid.UserRepository.GetConnection () [0x0008f] in c:\Development\UserSolution\User_Droid\UserRepository.cs:37 
  at User_Droid.UserRepository.CreateUser (User_Droid.User user, System.String& errorMessage) [0x00002] in c:\Development\UserSolution\User_Droid\UserRepository.cs:79 }
Comment 1 Esteban Troscé 2015-02-25 14:00:22 UTC
You don't have to buy sqlcipher to get encryption support: https://www.zetetic.net/sqlcipher/open-source/

As stated in the above link SQLCipher for Android Community Edition binaries are made available as a free service to the community here: https://s3.amazonaws.com/sqlcipher/3.2.0/sqlcipher-for-android-community-v3.2.0.zip
Comment 2 Cody Beyer (MSFT) 2016-04-28 01:25:02 UTC
# Description

The following exception is thrown when attempting to use a password for a SQLite Database.

>2016-04-27 18:10:14.256 TestSqliteApp[718:67770]   at Mono.Data.Sqlite.SQLite3.SetPassword (System.Byte[] passwordBytes) [0x00000] in /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:935 
  at Mono.Data.Sqlite.SqliteConnection.Open () [0x002f3] in /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteConnection.cs:895 
  at TestSqliteApp.ViewController.ViewDidLoad () [0x0002d] in /Users/codybeyer/Downloads/TestSqliteApp/ViewController.cs:25 

# Sample

Attached

# Steps to Reproduce

1. Download Sample
2. Deploy to iOS Simulator 

# Expected Results

Database should open

# Actual Results

Exception is thrown as described 

# Versions

=== Xamarin Studio Business ===

Version 6.0 (build 4968)
Installation UUID: 70640bf4-5398-4934-afed-9da3bfa3a4df
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000122

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.Mac ===

Version: 2.8.0.244 (Xamarin Business)

=== Xamarin.Android ===

Version: 6.1.0.37 (Xamarin Business)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 25.1.1
SDK Platform Tools Version: 23.1.0
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: 9.8.0.244 (Xamarin Business)
Hash: 977921b
Branch: cycle7
Build date: 2016-04-07 14:20:17-0400

=== Xamarin Inspector ===

Version: 0.8.0.0
Hash: dc081aa
Branch: master
Build date: Tue Apr 26 23:07:44 UTC 2016

=== Build Information ===

Release ID: 600004968
Git revision: ab7092ce63351276394f283e4f9c8646baf51fce
Build date: 2016-04-08 09:30:34-04
Xamarin addins: be0a0aef6ec8b075b4ba4690bd147d1e33c2abd7
Build lane: monodevelop-lion-cycle7

=== Operating System ===

Mac OS X 10.11.4
Darwin Cody-MBP.local 15.4.0 Darwin Kernel Version 15.4.0
	Fri Feb 26 22:08:05 PST 2016
	root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.8.0.0
Comment 3 Cody Beyer (MSFT) 2016-04-28 01:25:19 UTC
Created attachment 15861 [details]
Sample
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2016-04-28 02:48:15 UTC
To be clear, the implementation that is missing in this case is a C method named `sqlite3_key()`. On Android, the method would be contained in a `.so` library named something like `libsqlite.so`. The implementation of the method would therefore not be part of Mono itself. Mono includes a P/Invoke for the method [1] so that users _may_ call the method _if_ the version of libsqlite that they are using happens to include the encryption methods. As mentioned in Comment 1, the version of libsqlite that is maintained by _Zetetic_ does include the encryption methods.

[1] https://github.com/mono/mono/blob/1157071aad84188b8a72aa15e26458d1d64df429/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/UnsafeNativeMethods.cs#L660
Comment 5 Marek Safar 2018-03-13 16:19:22 UTC
We don't support this but you can use https://github.com/praeclarum/sqlite-net which has support for SQLCipher