Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1080977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:06:28+00:00 2026-05-16T22:06:28+00:00

I have been trying to encrypt/ decrypt a sqlite database in my iPhone project.

  • 0

I have been trying to encrypt/ decrypt a sqlite database in my iPhone project. I am able to encrypt the database by using the reKey method. But I am unable to decrypt it.
I have kept my sqlite.db file in a folder. Currently trying it on a simulator.

Code snippet:

[[SQLiteDB sharedSQLiteDB] open:<path to the folder> withKey:@""];

[[SQLiteDB sharedSQLiteDB] reKey:@"abc"];

[[SQLiteDB sharedSQLiteDB] close];

[[SQLiteDB sharedSQLiteDB] open:<path to the folder> withKey:@"abc"];

[[SQLiteDB sharedSQLiteDB] reKey:@""];

…..

- (BOOL)open:(NSString *)path withKey:(NSString *)masterKey {

    if (sqlite3_open([path fileSystemRepresentation], &_db) != SQLITE_OK) {
        NSLog(@"SQLite Opening Error: %s", sqlite3_errmsg(_db));
        return NO;
    }

    if(masterKey)
        sqlite3_exec(_db, [[NSString stringWithFormat:@"PRAGMA key = '%@'", masterKey] UTF8String], NULL, NULL, NULL);

    if (sqlite3_exec(_db, (const char*) "SELECT count(*) FROM sqlite_master", NULL, NULL, NULL) != SQLITE_OK)
    {
        [self close];
        NSLog(@"SQLite Key Error!");
        return NO;
    }

    filePath = [path retain];
    return YES;
}

……

- (void)reKey:(NSString *)masterKey
{
    sqlite3_exec(_db, [[NSString stringWithFormat:@"PRAGMA rekey = '%@'", masterKey] UTF8String], NULL, NULL, NULL);

}

I have read the posts on this topic in sqlcipher google groups, but I am unable to decrypt it. Any help would be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:06:29+00:00Added an answer on May 16, 2026 at 10:06 pm

    Reposing from the mailing list:

    If you are trying to take an existing non-encrypted database, encrypt it, and then decrypt it back, our recommended approach is not to use rekey, but instead to use ATTACHed databases to copy data between a standard and an sqlcipher database. There is more information and a concrete example here:

    http://www.zetetic.net/blog/2009/12/29/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher/

    If instead, you are just trying to use sqlcipher to encrypt data in general (i.e. with no conversion from a pre-existing database), then you just need to use sqlite3_key. You basically just open the database, provide the key and then make sql calls. There are no separate encryption / decryption steps – all of that is handled on the fly by the sqlcipher code. In the code you posted previously, you’d never call rekey at all. Each time you open the database you call PRAGMA key, and then run a quick check to ensure that sqlite_master is readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.