# Unable to decrypt encrypted database in swift 3

**URL:** <https://discuss.zetetic.net/t/unable-to-decrypt-encrypted-database-in-swift-3/2509>\
**Category:** SQLCipher\
**Created:** [November 28, 2017, 5:00am UTC](https://discuss.zetetic.net/t/unable-to-decrypt-encrypted-database-in-swift-3/2509 "2017-11-28T05:00:01Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [November 29, 2017, 2:58pm UTC](https://discuss.zetetic.net/t/unable-to-decrypt-encrypted-database-in-swift-3/2509/5 "2017-11-29T14:58:50Z")

</div>

@Ganesh_Padole

You’re going to need two separate paths:

1. The current encrypted database path that you’re going to need to sqlite3\_open and key.
2. The plain text database path that’s going to be used for sqlcipher\_export() for migrating from your encrypted database to plain text.

Currently both of these are are using the same path:

> [@Ganesh\_Padole](#):
>
> let newDstPath11 = String(format: “%@/Documents/encrypted1.sqlite”,NSHomeDirectory())

So why don’t we rename this one to be a little clearer:

```auto
let encryptedDbPath = String(format: "%@/Documents/encrypted1.sqlite",NSHomeDirectory())

```

And create another path for the output plain text db

```auto
let plaintextDbPath = String(format: "%@/Documents/plaintext1.sqlite",NSHomeDirectory())

```

Now when opening you’re going to want to use the encrypted db path:

```auto
// first open encrypted database
    if (sqlite3_open(encryptedDbPath, &db) == SQLITE_OK) {
...

```

but then when attaching the plaintext db to be exported you’re going to want to use the plain text db path:

```auto
let newQuery1 = "ATTACH DATABASE '\(plaintextDbPath)' AS plaintext KEY '';"

```

Let me know if this resolves the issue for you.

Cheers,  
Micah

---

_[View the full topic](https://discuss.zetetic.net/t/unable-to-decrypt-encrypted-database-in-swift-3/2509)._
