# Encrypted DB in swift-iOS via FMDB, can not open in SQL DB Browser

**URL:** <https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813>\
**Category:** Issues\
**Created:** [February 1, 2021, 7:47am UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813 "2021-02-01T07:47:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkhnaydn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/gkhnaydn/32/1559_2.png) [@gkhnaydn](https://discuss.zetetic.net/u/gkhnaydn)\
**Post date:** [February 1, 2021, 7:47am UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/1 "2021-02-01T07:47:14Z")

</div>

Hi,

Nowadays I try to encrypt a database with metadata below:

> ```
> override init() {
> super.init()
> path = BackUpMigrationHelper.migrateToBackupDatabaseIfNeeded()
> 
> dbQueue = FMDatabaseQueue(path: path)
> dbQueue.inDatabase { database in
>                    
> // executeStatements method of FMDB uses sqlite3_exec
> let isPasswordSet = database.setKey("password")
> database.executeStatements("PRAGMA cipher_memory_security = OFF")
> database.executeStatements("PRAGMA kdf_iter = 64000")
> database.executeStatements("PRAGMA cipher_page_size = 1024")
> database.executeStatements("PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1")
> database.executeStatements("PRAGMA cipher_hmac_algorithm = HMAC_SHA1")
> debugPrint("password set : \(isPasswordSet)")
> }
> 
> try? createTableIfNeeded(DatabaseMessageTable.current)
> }
> 
> public func createTableIfNeeded(_ table: DatabaseMessageTable) throws {
> var error: Error?
> 
> dbQueue.inTransaction { (database, _) in
> do {
> try database.executeUpdate(
> "CREATE TABLE IF NOT EXISTS \(table.name)(\(id) INTEGER PRIMARY KEY AUTOINCREMENT,\(txnid) TEXT,\(rawxml) TEXT);", values: [])
> 
> Logger.logVerbose("DatabaseHelper. createOrOpenDB. SUCCESS")
> } catch let dbError {
> Logger.logError("DatabaseHelper. createOrOpenDB. FAILURE. \(dbError.localizedDescription)")
> error = dbError
> }
> }
> 
> if let error = error {
> throw error
> }
> }
> 
> ```

when I run the code above, I see that the database created on the path, then I try to open it in SQL DB Browser with metadata, however it always fails.

Additionally SQLCipher version is 4.4.2 and FMBD version is 2.7.5.

On the other hand, I realized that ‘Google-Mobile-Ads-SDK’ pod (includes “sqlite3”) in another target non related with SQLCipher inserted target. Does it make fail? For example:

> ```
> target 'TestProject' do
> use_frameworks!
> inherit! :search_paths
> pod 'Google-Mobile-Ads-SDK'
> end
> 
> ```

> ```
> target 'FMDBTarget' do
> use_frameworks!
> inherit! :search_paths
> pod 'FMDB'
> pod 'FMDB/standalone'
> pod 'FMDB/SQLCipher'
> end
> 
> ```

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [February 1, 2021, 4:55pm UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/2 "2021-02-01T16:55:38Z")

</div>

@gkhnaydn

Thanks for your interest in SQLCipher and for posting to the discussion forum. Yes, Google-Mobile-Ads-SDK does include a reference to sqlite3 which can cause undefined behavior with SQLCipher. You can see my response here for additional information: [Cannot open encrypted database with SQLCipher 4 - #4 by mmoore](https://discuss.zetetic.net/t/cannot-open-encrypted-database-with-sqlcipher-4/3654/4)

---

<div class="post-metadata">

**Author:** ![gkhnaydn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/gkhnaydn/32/1559_2.png) [@gkhnaydn](https://discuss.zetetic.net/u/gkhnaydn)\
**Post date:** [February 2, 2021, 6:28am UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/3 "2021-02-02T06:28:57Z")

</div>

Actually when I try to install SQLCipher pod in a new project, it goes on to fail again.

> target ‘SQLCipherTestProject’ do
> 
> ```
> pod 'FMDB'
> pod 'FMDB/standalone'
> pod 'FMDB/SQLCipher'
> 
> ```
> 
> end

I can encrypt database with the metadata at the question above. However when I try to open the db at SQL BD Browser with the same metada again, it does not open. I think that there is a problem about executing PRAGMA commands for iOS, because the main reason looks like assigning metadata settings problem.

Althought i try to a lot of way to settings metadata, i could not achive. I have searched about the topic anywhere but there is no example about metadata for iOS.

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [February 2, 2021, 3:43pm UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/4 "2021-02-02T15:43:39Z")

</div>

@gkhnaydn

> [@gkhnaydn](#):
>
> target ‘SQLCipherTestProject’ do
> 
> ```auto
> pod 'FMDB'
> pod 'FMDB/standalone'
> pod 'FMDB/SQLCipher'
> 
> ```
> 
> end

You should only need to include

```auto
pod 'FMDB/SQLCipher'

```

in your Podfile.

If you look at the FMDB podspec you’ll notice that standalone is including standard sqlite3 which you don’t want: [https://github.com/ccgus/fmdb/blob/master/FMDB.podspec#L15](https://github.com/ccgus/fmdb/blob/master/FMDB.podspec#L15)

---

<div class="post-metadata">

**Author:** ![gkhnaydn](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/gkhnaydn/32/1559_2.png) [@gkhnaydn](https://discuss.zetetic.net/u/gkhnaydn)\
**Post date:** [February 3, 2021, 6:07am UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/5 "2021-02-03T06:07:50Z")

</div>

Yes, that is it. Thank you so much @mmoore you save my time thanks again and again. I could not think this way.

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [February 3, 2021, 4:17pm UTC](https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/6 "2021-02-03T16:17:56Z")

</div>

@gkhnaydn

Glad I could help and you were able to resolve the issue.
