# Not able to read Data from Encrypted Database in IOS

**URL:** <https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692>\
**Category:** SQLCipher\
**Created:** [July 29, 2015, 9:55am UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692 "2015-07-29T09:55:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharmasneha](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sharmasneha](https://discuss.zetetic.net/u/sharmasneha)\
**Post date:** [July 29, 2015, 9:55am UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/1 "2015-07-29T09:55:09Z")

</div>

Hi, In ios, I am using SQLCipher for encrypting Database which was successfully Integrated into my Project.However, when i tried to read data from Encrypted Database i got error

## file is encrypted or is not a database

Using Xcode ver - 6.3.2

Sharing the code below

-(void)readDataBase{

```
NSString *encryptedPath = [NSString stringWithFormat:@"%@/Documents/ABC_encrypted.sqlite",NSHomeDirectory()];

sqlite3 *database;
if (sqlite3_open([encryptedPath UTF8String], &database) == SQLITE_OK) {
    
    const char* key = [@"test123" UTF8String];
    char *error = nil;
    
    sqlite3_key(database, key, (int)strlen(key));
    
    if (sqlite3_exec(database,"SELECT count(*) FROM sqlite_master;", NULL, NULL, &error) == SQLITE_OK) {
                NSLog(@"correct password");
    } else {
        NSLog(@"incorrect password");
        NSLog(@"%s",error);
     }
    sqlite3_close(db);
}

```

}

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [July 29, 2015, 12:47pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/2 "2015-07-29T12:47:10Z")

</div>

Hello @sharmasneha

Was the database `/Documents/ABC_encrypted.sqlite` already encrypted, or was it a plain text SQLite database when you were attempting to open and key it?

---

<div class="post-metadata">

**Author:** ![sharmasneha](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sharmasneha](https://discuss.zetetic.net/u/sharmasneha)\
**Post date:** [July 29, 2015, 3:22pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/3 "2015-07-29T15:22:22Z")

</div>

Yes, it was encrypted one.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [July 29, 2015, 4:03pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/4 "2015-07-29T16:03:27Z")

</div>

Hello @sharmasneha

Can you pull the database from the simulator and verify whether you can open and query the database using the SQLCipher command line shell?

---

<div class="post-metadata">

**Author:** ![sharmasneha](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sharmasneha](https://discuss.zetetic.net/u/sharmasneha)\
**Post date:** [July 31, 2015, 2:17pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/5 "2015-07-31T14:17:17Z")

</div>

Hi Nick,  
Thanks for your help.I got solution.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [July 31, 2015, 2:33pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/6 "2015-07-31T14:33:18Z")

</div>

Hi @sharmasneha

I’m glad to hear everything is working for you. Take care!

---

<div class="post-metadata">

**Author:** ![sharmasneha](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sharmasneha](https://discuss.zetetic.net/u/sharmasneha)\
**Post date:** [August 19, 2015, 2:30pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/7 "2015-08-19T14:30:18Z")

</div>

Hi Nick,  
I am facing one issue. while performing update query ,I am getting message “data not updated coz database is locked”. Could you please help me on this.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [August 19, 2015, 9:51pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/8 "2015-08-19T21:51:02Z")

</div>

Hello @sharmasneha

Is your database connection open? The sample of code you posted above appears to close the database handle once you validate whether or not the password is valid. Can you create a sample application that replicates the issue, we would be glad to help.

---

<div class="post-metadata">

**Author:** ![sharmasneha](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sharmasneha](https://discuss.zetetic.net/u/sharmasneha)\
**Post date:** [January 13, 2016, 6:05am UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/9 "2016-01-13T06:05:13Z")

</div>

Hi Nick,  
When i perform insertion(inserting data on multiple Tables ) and updation, my app performance is very slow. I am using Singleton Object to perform database operations and i am not repeatedly opening and closing Database connections.Could you please help me on this.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [January 13, 2016, 2:37pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/10 "2016-01-13T14:37:06Z")

</div>

Hello @sharmasneha

We provide guidance on SQLCipher performance [here](https://discuss.zetetic.net/t/sqlcipher-performance/14). Could you review that documentation and make the appropriate adjustments to your application?

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [February 1, 2016, 5:52pm UTC](https://discuss.zetetic.net/t/not-able-to-read-data-from-encrypted-database-in-ios/692/11 "2016-02-01T17:52:53Z")

</div>

A post was merged into an existing topic: [SQLCipher Performance](https://discuss.zetetic.net/t/sqlcipher-performance/14)
