Not able to read Data from Encrypted Database in IOS


#1

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);
}

}


#2

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?


#3

Yes, it was encrypted one.


#4

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?


#5

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


#6

Hi @sharmasneha

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


#7

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.


#8

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.


#9

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.


#10

Hello @sharmasneha

We provide guidance on SQLCipher performance here. Could you review that documentation and make the appropriate adjustments to your application?


#11

A post was merged into an existing topic: SQLCipher Performance