Why Sqlcipher is not creating an encrypted database through my .NetCore app?

Hi:

Newbie here trying to hook up Sqlcipher into .NetCore Sqlite application.
We are using DevExpress XPO.

I’ve tried mirroring the steps outlined in SQLCipher documentation page.
It runs without errors or exceptions, but it doesn’t to do the encryption.

Here is a sample snippet of my code:

var unitOfWork =  new UnitOfWork(IDataLayer);
unitOfWork.ExecuteNonQuery($"PRAGMA key = '{myKeyValue}';");
unitOfWork.ExecuteNonQuery($"PRAGMA cipher_license = '{myCipherLicense}';");
unitOfWork.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS Model(id, a,b);");

At this point, an encrypted DB file should be created.

I attempt to run the following without using key/cipher key:
try
{
var unitOfWork = new UnitOfWork(IDataLayer);
unitOfWork.ExecuteNonQuery(“INSERT INTO Model (id, a, b) VALUES (‘id’, ‘a’, ‘b’);”);
}
catch (Exception ex)
{
}

I would expect to throw an exception at this point indicated I tried to access DB without key/cipher license.

I am also able to open the generated DB in SqliteStudio and view data with no restrictions.

Here are the NuGet Packages I am referencing:
PackageReference Include=“DevExpress.Xpo” Version=“23.1.3”
PackageReference Include=“Microsoft.Data.Sqlite.Core” Version=“7.0.9”
PackageReference Include=“SQLitePCLRaw.bundle_e_sqlcipher” Version=“2.1.5”
PackageReference Include=“SQLitePCLRaw.bundle_zetetic” Version=“2.1.5”
PackageReference Include=“System.Data.SQLite” Version=“1.0.117”
PackageReference Include=“zetetic-sqlcipher-windows-fips” Version=“4.5.3”

I feel like I’m missing something somewhere either in setup steps or environment.
Can someone help get me pointed in the right direction?

Is this more a question for the DevExpress (xpo) folks?

Thanks

Hi @JuanBucz,

I am not familiar with DevExpress XPO, do you know if it supports SQLCipher? One way to determine at runtime whether or not the SQLCipher library itself is being loaded into memory is to execute the following PRAGMA statement which will return a string value representing the SQLCipher library version. Can you execute this query to see what is identified?

PRAGMA cipher_version;

Hello @JuanBucz - That would be a potential behavior if a standard SQLite library is loaded instead of SQLCipher. To test this, please capture the result of this statement:

PRAGMA cipher_version;

If SQLCipher was successfully loaded it will return a string like 4.5.3 zetetic. If you do not get a value out, then SQLCipher is not in use.

In terms of your NuGet packages, one thing I would note is that you should not be referencing SQLitePCLRaw.bundle_e_sqlcipher if you are using official SQLCipher builds, you should only reference SQLitePCLRaw.bundle_zetetic.

Finally, I noticed that you are referencing zetetic-sqlcipher-windows-fips. That is a special package that is only available through the SQLCipher Enterprise program. If you are an Enterprise program Licensee, or using a commercial package, please contact us at support@zetetic.net so we can help you further.

Hi:

I was able to create a small test app and get it working with encryptions using your recommendations.

However, our actual application is still having the same issues mentioned in the support ticket.

From my end, I was going to add the same NUGet pkgs to the test app that we are using in our full fledged application.

What’s the best way to proceed to debug and track this down?

I verified that we do have an enterprise license.

Thanks

Hello @JuanBucz - I think the best bet is for you to contact us at support@zetetic.net. This way we can understand a bit more about the differences between your full application. When you write in, please let us know the company your Enterprise License is under so we can verify. We’ll be happy to help you further. Thanks!

Ha!
Figured it out.
Unbeknownst to me, we were creating some tables early on in the initialization process before I was attempting to encrypt the database.

I reordered our initialization workflow and things now work as expected.

Thx for the quick responses.
JohnB