# Encrypte existing db

**URL:** https://discuss.zetetic.net/t/encrypte-existing-db/4190
**Category:** SQLCipher
**Created:** [January 2, 2020, 6:31pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190 "2020-01-02T18:31:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![phunction](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@phunction](https://discuss.zetetic.net/u/phunction)
#### Post date: [January 2, 2020, 6:31pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190/1 "2020-01-02T18:31:10Z")

</div>

Hi, is it possible to encrypt an existing regular sqlite database file? I am using V 3.4.1

Thanks

---

<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: [January 2, 2020, 6:44pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190/2 "2020-01-02T18:44:59Z")

</div>

@phunction

You can use the [sqlcipher\_export()](https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export) convenience function to encrypt an already existing plain text sqlite database. Specifically, you’ll want to have a look at “Example 1: Encrypt a Plaintext Database” from that link.

---

<div class="post-metadata">

### Author: ![phunction](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@phunction](https://discuss.zetetic.net/u/phunction)
#### Post date: [January 3, 2020, 4:39pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190/3 "2020-01-03T16:39:56Z")

</div>

Thanks, is there an example that shows how to do this through .net, I normally use SqliteConnection and SqliteCommand. I believe I can just pass SELECT sqlcipher\_export(‘encrypted’); through SqliteCommand however I am not sure how to implement the ATTACH part?

---

<div class="post-metadata">

### Author: ![phunction](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@phunction](https://discuss.zetetic.net/u/phunction)
#### Post date: [January 3, 2020, 5:13pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190/4 "2020-01-03T17:13:40Z")

</div>

Nevermind, I figured it out.

---

<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: [January 3, 2020, 10:20pm UTC](https://discuss.zetetic.net/t/encrypte-existing-db/4190/5 "2020-01-03T22:20:21Z")

</div>

@phunction

Glad to hear you were able to get it to work.
