I'm trying to decrypt an encrypted SQLite DB (in .Net). According to Zetetic's documentation (https://www.zetetic.net/sqlcipher/sqlcipher-api/) one can use sqlcipher_export for this purpose, like so:
var connection = new SqliteConnection(string.Format("Data Source={0}", fullDbPath));
connection.Open();
var key = //get it from somewhere
var command = connection.CreateCommand();
command.CommandText = "SELECT quote($password);";
command.Parameters.AddWithValue("$password", key);
var quotedPassword = (string)command.ExecuteScalar();
command.Parameters.Clear();
command.CommandText = $"PRAGMA key = {quotedPassword}; ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';SELECT sqlcipher_export('plaintext');DETACH DATABASE plaintext";
command.ExecuteNonQuery();
However, this throws an exception Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 1: 'table "__EFMigrationsHistory" already exists'.'
I can't figure out what I'm doing wrong, any ideas?