sqlite-net
sqlite-net copied to clipboard
Encryption is not working
I am using the sqlite-net-cipher package to create an encrypted database as such
SQLiteConnectionString options = new SQLiteConnectionString(
config["LocalDatabase:ConnectionString"],
false,
key: "test-sample-key",
postKeyAction: db =>
{
db.Execute("PRAGMA cipher_compatibility = 3;");
}
);
var dbInstance = new SQLiteConnection(options);
The db is created without any issues and I can perform all operations without any issues as well. However It seems that the database isn't being encrypted, evident by the fact that when I open the db file with a tool like DB Browser for SQLite , I can open the database and look at all the records and the tool doesn't ask me for any key.
This is my proj file for reference:
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<OutputType>Exe</OutputType>
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>x64</PlatformTarget>
<UserSecretsId>dotnet-SampleApp-1f045254-77f3-4330-9006-740a5c6e7f15</UserSecretsId>
<Configurations>Release;Debug</Configurations>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.4" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Database" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="Quartz" Version="3.8.0" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.8.0" />
<PackageReference Include="sqlite-net-sqlcipher" Version="1.8.116" />
</ItemGroup>
<ItemGroup>
<None Remove="DTOs\" />
</ItemGroup>
<ItemGroup>
<Folder Include="DTOs\" />
</ItemGroup>
</Project>
Please advise on how I can proceed with this. I have looked at all the other issues in the repo and none has helped. Any help is really appreciated.
Any update on this? I have the same issue.
I've installed the nugets in .NET 8 as follows FYI.
<PackageReference Include="sqlite-net-sqlcipher" Version="1.9.172" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.9" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.9" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.9" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.9" />
Any update on this? I have the same issue.
I've installed the nugets in .NET 8 as follows FYI.
<PackageReference Include="sqlite-net-sqlcipher" Version="1.9.172" /> <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.9" /> <PackageReference Include="SQLitePCLRaw.core" Version="2.1.9" /> <PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.9" /> <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.9" />
I haven't been able to find any solution unfortunately.
@ShimantaKB-Tunnel ,
I have replicated this repo as an exmaple too but this doesn't work too :(
https://github.com/jfversluis/MauiEncryptedSqliteSample/tree/main.
Anyone got the solution/workaround for this? I have been desperately looking for the solution.