{"id":18982724,"url":"https://github.com/bezzad/sqliteencryption","last_synced_at":"2025-11-10T23:03:38.987Z","repository":{"id":92822722,"uuid":"187471881","full_name":"bezzad/SQLiteEncryption","owner":"bezzad","description":"SQLite Encryption using Entity Framework Core (EFCore)","archived":false,"fork":false,"pushed_at":"2019-05-19T13:41:50.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T11:43:17.974Z","etag":null,"topics":["sql","sqlite","sqlite-cipher","sqlite-encription"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bezzad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-19T12:10:15.000Z","updated_at":"2021-11-16T13:05:56.000Z","dependencies_parsed_at":"2023-03-16T08:45:44.722Z","dependency_job_id":null,"html_url":"https://github.com/bezzad/SQLiteEncryption","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bezzad%2FSQLiteEncryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bezzad%2FSQLiteEncryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bezzad%2FSQLiteEncryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bezzad%2FSQLiteEncryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bezzad","download_url":"https://codeload.github.com/bezzad/SQLiteEncryption/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239987293,"owners_count":19729776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sql","sqlite","sqlite-cipher","sqlite-encription"],"created_at":"2024-11-08T16:14:27.360Z","updated_at":"2025-11-10T23:03:38.952Z","avatar_url":"https://github.com/bezzad.png","language":null,"readme":"# Encryption in Microsoft.Data.Sqlite\nOne of the frequently asked questions about [Microsoft.Data.Sqlite](https://github.com/aspnet/Microsoft.Data.Sqlite) is: How do I encrypt a database? I think that one of the main reasons for this is because [System.Data.SQLite](http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki) comes with an unsupported, Windows-only encryption codec that can be used by specifying `Password` (or `HexPassword`) in the connection string. The official releases of SQLite, however, don't come with encryption.\n\n[SEE](http://www.hwaci.com/sw/sqlite/see.html), [SQLCipher](https://www.zetetic.net/sqlcipher/), [SQLiteCrypt](http://sqlite-crypt.com/index.htm) \u0026 [wxSQLite3](https://github.com/utelle/wxsqlite3) are just some of the solutions I've found that can encrypt SQLite database files. They all seem to follow the same general pattern, so this post applies to all of them.\n\n## Bring Your Own Library\nThe first step is to add a version of the native `sqlite3` library to you application that has encryption. `Microsoft.Data.Sqlite` depends on [SQLitePCL.raw](https://github.com/ericsink/SQLitePCL.raw) which makes it very easy to use SQLCipher.\n\n```\nInstall-Package Microsoft.Data.Sqlite.Core\nInstall-Package SQLitePCLRaw.bundle_sqlcipher\n```\nSQLitePCL.raw also enables you to bring your own build of SQLite, but we won't cover that in this post.\n\n## Specify the Key\nTo enable encryption, Specify the key immediately after opening the connection. Do this by issuing a `PRAGMA key` statement. It may be specified as either a string or BLOB literal. SQLite, unfortunately, doesn't support parameters in `PRAGMA` statements.\n\n``` C#\nconnection.Open();\nusing (var command = connection.CreateCommand())\n{\n    command.Parameters.Clear();\n    command.CommandText = $\"PRAGMA key = '{Password}';\";\n    command.ExecuteNonQuery();\n\n    return connection;\n}\n\n// Interact with the database here\n```\n\n## Rekey the Database\nIf you want to change the encryption key of a database, issue a `PRAGMA rekey` statement. To decrypt the database, specify `NULL`, ex: `PRAGMA rekey='';`.\n\n``` C#\nconnection.Open();\nusing (var command = connection.CreateCommand())\n{\n    command.Parameters.Clear();\n    command.CommandText = $\"PRAGMA key='{Password}';\";\n    command.ExecuteNonQuery();\n\n    command.CommandText = $\"PRAGMA rekey='{NewPassword}';\";\n    command.ExecuteNonQuery();\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbezzad%2Fsqliteencryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbezzad%2Fsqliteencryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbezzad%2Fsqliteencryption/lists"}