You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-2Lines changed: 17 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,8 +171,19 @@ The T in `db.Query<T>` specifies the object to create for each row. It can be a
171
171
172
172
## Using an encrypted database file
173
173
174
-
Add the nuget [SQLitePCLRaw.bundle_e_sqlcipher](https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlcipher) to your common project.
175
-
Then add this code right after opening or creating the db, and before any other db call:
174
+
Add the nuget [SQLitePCLRaw.bundle_e_sqlcipher](https://www.nuget.org/packages/SQLitePCLRaw.bundle_e_sqlcipher) to your common project.
175
+
176
+
### Option 1 (preferred)
177
+
178
+
Use the `encryptionKey` parameter in the constructor of `SQLiteConnection`.
179
+
180
+
Then use the db as usual.
181
+
182
+
With this option, the encryption key is kept in memory. That should not be an issue.
183
+
184
+
185
+
### Option 2 (roots)
186
+
Add this code right after opening or creating the db, and before any other db call:
176
187
177
188
```c#
178
189
stringkey="yourCryptingKey";
@@ -182,8 +193,12 @@ if(ok != "ok")
182
193
thrownewException("Bad key");
183
194
```
184
195
196
+
If you will use `InsertAll(), InsertOrUpdateAll(), ReplaceAll()` you must create a new class deriving from `SQLiteConnection` and override `Clone()` so it sets the encryption key after cloning.
197
+
185
198
Then use the db as usual.
186
199
200
+
### Final Thoughts
201
+
187
202
You can read the version of the cypher lib using the code. Check the [Zenetik](//https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_version) website for more information.
// copies of the Software, and to permit persons to whom the Software is
14
-
// furnished to do so, subject to the following conditions:
11
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
12
+
// in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+
// copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
15
14
//
16
-
// The above copyright notice and this permission notice shall be included in
17
-
// all copies or substantial portions of the Software.
15
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18
16
//
19
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
-
// THE SOFTWARE.
26
-
//
17
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
20
28
21
usingSystem;
29
22
usingSystem.Collections;
@@ -40,7 +33,7 @@
40
33
namespaceSQLite.Net2
41
34
{
42
35
/// <summary>
43
-
/// Represents an open connection to a SQLite database.
36
+
/// Represents an open connection to a SQLite database.
44
37
/// </summary>
45
38
publicclassSQLiteConnection:IDisposable
46
39
{
@@ -64,6 +57,7 @@ public class SQLiteConnection : IDisposable
64
57
privatebool_open;
65
58
privateStopwatch?_sw;
66
59
privatereadonlySQLiteOpenFlagsdatabaseOpenFlags;
60
+
privatereadonlystringencryptionKey;
67
61
68
62
publicIBlobSerializer?Serializer{get;}
69
63
publicstringDatabasePath{get;}
@@ -84,82 +78,40 @@ static SQLiteConnection()
84
78
}
85
79
}
86
80
87
-
/// <summary>
88
-
/// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
89
-
/// </summary>
90
-
/// <param name="sqlitePlatform"></param>
91
-
/// <param name="databasePath">
92
-
/// Specifies the path to the database file.
93
-
/// </param>
94
-
/// <param name="storeDateTimeAsTicks">
95
-
/// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
96
-
/// absolutely do want to store them as Ticks in all new projects. The option to set false is
97
-
/// only here for backwards compatibility. There is a *significant* speed advantage, with no
98
-
/// down sides, when setting storeDateTimeAsTicks = true.
99
-
/// </param>
100
-
/// <param name="serializer">
101
-
/// Blob serializer to use for storing undefined and complex data structures. If left null
102
-
/// these types will thrown an exception as usual.
103
-
/// </param>
104
-
/// <param name="tableMappings">
105
-
/// Exisiting table mapping that the connection can use. If its null, it creates the mappings,
106
-
/// if and when required. The mappings are also created when an unknown type is used for the first
107
-
/// time.
108
-
/// </param>
109
-
/// <param name="extraTypeMappings">
110
-
/// Any extra type mappings that you wish to use for overriding the default for creating
111
-
/// column definitions for SQLite DDL in the class Orm (snake in Swedish).
112
-
/// </param>
113
-
/// <param name="resolver">
114
-
/// A contract resovler for resolving interfaces to concreate types during object creation
/// This support scenarios where a code needs to create a transaction, while leaving the current connection transactionless (ie: sharable with other codes), as a transaction creates a state in this object.
86
+
///
87
+
/// This is used by *All() methods.
88
+
///
89
+
/// Override it if you have not called the constructor with an encryption key and you database is encrypted.
/// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
95
+
/// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
133
96
/// </summary>
134
-
/// <param name="sqlitePlatform"></param>
135
-
/// <param name="databasePath">
136
-
/// Specifies the path to the database file.
137
-
/// </param>
97
+
/// <param name="databasePath">Specifies the path to the database file. </param>
138
98
/// <param name="openFlags"></param>
139
99
/// <param name="storeDateTimeAsTicks">
140
-
/// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
141
-
/// absolutely do want to store them as Ticks in all new projects. The option to set false is
142
-
/// only here for backwards compatibility. There is a *significant* speed advantage, with no
143
-
/// down sides, when setting storeDateTimeAsTicks = true.
144
-
/// </param>
145
-
/// <param name="serializer">
146
-
/// Blob serializer to use for storing undefined and complex data structures. If left null
147
-
/// these types will thrown an exception as usual.
100
+
/// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
101
+
/// absolutely do want to store them as Ticks in all new projects. The option to set false is
102
+
/// only here for backwards compatibility. There is a *significant* speed advantage, with no
103
+
/// down sides, when setting storeDateTimeAsTicks = true.
148
104
/// </param>
105
+
/// <param name="serializer">Blob serializer to use for storing undefined and complex data structures. If left null these types will thrown an exception as usual.</param>
149
106
/// <param name="tableMappings">
150
-
/// Exisiting table mapping that the connection can use. If its null, it creates the mappings,
151
-
/// if and when required. The mappings are also created when an unknown type is used for the first
152
-
/// time.
153
-
/// </param>
154
-
/// <param name="extraTypeMappings">
155
-
/// Any extra type mappings that you wish to use for overriding the default for creating
156
-
/// column definitions for SQLite DDL in the class Orm (snake in Swedish).
157
-
/// </param>
158
-
/// <param name="resolver">
159
-
/// A contract resovler for resolving interfaces to concreate types during object creation
/// Existing table mapping that the connection can use. If its null, it creates the mappings,
108
+
/// if and when required. The mappings are also created when an unknown type is used for the first time.
109
+
/// </param>
110
+
/// <param name="extraTypeMappings">Any extra type mappings that you wish to use for overriding the default for creating column definitions for SQLite DDL in the class Orm (snake in Swedish).</param>
111
+
/// <param name="resolver">A contract resovler for resolving interfaces to concreate types during object creation</param>
112
+
/// <param name="encryptionKey">When using SQL CIPHER, automatically sets the key (you won't need to override Clone() in this case)</param>
0 commit comments