Search code examples
c#.netsqliteentity-framework-coresqlcipher

Microsoft.Data.Sqlite issue with apostrophe characters in password


I'm using EF Core 6 with the MS SQLite driver and the SQLitePCLRaw.bundle_e_sqlcipher so the database is being encrypted by SqlCipher. if I pass a apostrophe character in the password then the apostrophe character is being doubled in the password. For example if I use the following connection string when creating a database:

@"Data Source=c:\temp\test.db;password=""123'"""

When I try to access the database the password to the database is 123''. I have tried using pragma key as well and get the same issue. I create a new database and then immediately execute the following SQLite Pragma command:

pragma key='123''' Note: the apostrophe is escaped with another apostrophe)

and again the password to access the database is set as 123''.


Solution

  • It turns out this is not a fault in EF Core, the MS SQLite Drivers or SqlCipher.

    I was using a program called SQLiteStudio to access the database and view the contents. The fault is in SQLiteStudio, if the password contains an apostrophe you have to enter it twice.

    I proved this by downloading a copy of DB Browser for Sqlite and this let me access the database by typing the correct password.

    Sorry for wasting peoples time!