mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Update README for cipher_page_size and kdf_iter SQLCipher pragmas
This commit is contained in:
1 parent
0a814ee1e7
commit
5bf54dc5c9
1 file changed
+6
-18
@@ -7379,31 +7379,19 @@ try clearDBQueue.inDatabase { db in
|
||||
|
||||
## Advanced configuration options for SQLCipher
|
||||
|
||||
There are two advanced configuration options that you can set for configuring SQLCipher that control aspects of the encryption and key generation process.
|
||||
Some advanced SQLCipher configuration steps must happen very early in the database lifetime, and you will have to use the `configuration.prepareDatabase` property in order to run them correctly:
|
||||
|
||||
```swift
|
||||
var configuration = Configuration()
|
||||
configuration.passphrase = "secret"
|
||||
configuration.cipherPageSize = .pageSize4K
|
||||
configuration.kdfIterations = 128000
|
||||
configuration.prepareDatabase = { db in
|
||||
try db.execute(sql: "PRAGMA cipher_page_size = 4096")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = 128000")
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: "...", configuration: configuration)
|
||||
```
|
||||
|
||||
### cipherPageSize
|
||||
|
||||
The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the [SQLCipher `PRAGMA cipher_page_size`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages.
|
||||
|
||||
The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `1024`.
|
||||
|
||||
> :point_up: **Note**: the same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown.
|
||||
|
||||
### kdfIterations
|
||||
|
||||
The `kdfIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the [SQLCipher `PRAGMA kdf_iter`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) configuration option).
|
||||
|
||||
The default `kdfIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default.
|
||||
|
||||
> :point_up: **Note**: the same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown.
|
||||
See [PRAGMA cipher_page_size](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) and [PRAGMA kdf_iter](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) for more information.
|
||||
|
||||
|
||||
## Backup
|
||||
|
||||
Reference in new issue
Block a user