mirror of
https://github.com/groue/GRDB.swift
synced 2026-12-04 05:08:44 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fd36d4075 | ||
|
|
0a2d5322f3 | ||
|
|
76c46029e1 |
No files matched your search
@@ -4620,10 +4620,10 @@ See [SQLCipher 4.0.0 Release](https://www.zetetic.net/blog/2018/11/30/sqlcipher-
|
||||
|
||||
**You can change the passphrase** of an already encrypted database.
|
||||
|
||||
When you use a [database queue](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue), open the database with the old passphrase, and then apply the new passphrase:
|
||||
When you use a [database queue](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue), open the database with the old passphrase, and then apply the new passphrase outside of a transaction:
|
||||
|
||||
```swift
|
||||
try dbQueue.write { db in
|
||||
try dbQueue.barrierWriteWithoutTransaction { db in
|
||||
try db.changePassphrase("newSecret")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -123,6 +123,8 @@ extension Database {
|
||||
}
|
||||
|
||||
/// Changes the passphrase used by an SQLCipher encrypted database.
|
||||
///
|
||||
/// This method must be called outside of a transaction.
|
||||
public func changePassphrase(_ passphrase: String) throws {
|
||||
guard var data = passphrase.data(using: .utf8) else {
|
||||
throw DatabaseError(message: "invalid passphrase")
|
||||
@@ -134,6 +136,8 @@ extension Database {
|
||||
}
|
||||
|
||||
/// Changes the passphrase used by an SQLCipher encrypted database.
|
||||
///
|
||||
/// This method must be called outside of a transaction.
|
||||
public func changePassphrase(_ passphrase: Data) throws {
|
||||
// FIXME: sqlite3_rekey is discouraged.
|
||||
//
|
||||
|
||||
@@ -164,7 +164,7 @@ let testBundle = Bundle(for: GRDBTestCase.self)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try dbQueue.barrierWriteWithoutTransaction { db in
|
||||
try db.changePassphrase("newSecret")
|
||||
}
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -212,7 +212,7 @@ let testBundle = Bundle(for: GRDBTestCase.self)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try dbQueue.barrierWriteWithoutTransaction { db in
|
||||
try db.changePassphrase(finalPassphrase)
|
||||
}
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
Reference in new issue
Block a user