I’m currently trying to encrypt SQLite database with official SEE extension when using Microsoft entity framework.
I’m able to encrypt database when using ADO.NET. However getting an error “You specified a password in the connection string, but the native SQLite library ‘e_sqlite3’ doesn’t support encryption” when using entity frame work.
Nuget Packages Used:
[Microsoft.EntityFrameWork.Core Microsoft.EntityFrameWork.Core.SQLite SQLite.Encryption.Extension System.Data.SQLite.Core]
Please can you advise how to fix this error with official SEE extension?
CustomDBContext.cs:
private readonly bool _created = false;
public CustomDbContext(DBContextOptions<CustomDbContext> options):base(options){
if(!_created)
{
_created = true;
Database.EnsureCreated();
}
}
public DbSet<SampleEntity> SampleEntities {get; set;}
Program.cs:
static void Main(string[] args)
{
var services = new ServiceCollection();
ConfigureService(services);
using ServiceProvider provider = services.BuildServiceProvider();
provider.GetService<ICustomDBContext>();
}
private static void ConfigureServices(ServiceCollection services)
{
string password = Convert.ToHexString(Encoding.Default.GetBytes("aes256:test");
SQLiteCommand.Execute("PRAGMA activate_extensions='see-7bb07b8d471d642e'", SQLiteExecuteType.NonQuery,@"Data Source=c:\users\test.db");
SQLiteConnectionStringBuilder connectionStringBuilder = new(){
ConnectionString = @"Data Source=c:\users\test.db;Password="+password};
SQLiteConnection conn = new(connectionStringBuilder.ConnectionString);
connection.Open();
connection.ChangePassword(password);
services.AddDbContext<CustomDBContext>(options => options.UseSqlite(connection));
}