title: Encrypting db for SQLCipher Issues
body: <p>I'm having problem with creating a new encrypted db.
  I've done research regarding about this and these are some solutions that I have tried.</p>
  
  <p>Using terminal 
  based on <a href="http://sqlcipher.net/design/" rel="nofollow">http://sqlcipher.net/design/</a></p>
  
  <pre><code>sqlite3 sqlcipher.db
  sqlite&gt; PRAGMA KEY='test123';
  sqlite&gt; CREATE TABLE t1(a,b);
  sqlite&gt; INSERT INTO t1(a,b) VALUES ('one for the money', 'two for the show');
  sqlite&gt; .quit
  
  ~ $ hexdump -C sqlcipher.db
  </code></pre>
  
  <p>running the hexdump still gives me non encrypted db text.</p>
  
  <p>Doing the attached way to existing Db in ios. </p>
  
  <pre><code>- (void)encryptDB
  {
      sqlite3 *unencrypted_DB;
      NSString *path_u = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
                          stringByAppendingPathComponent:@"unencrypted.db"];
  
      if (sqlite3_open([path_u UTF8String], &amp;unencrypted_DB) == SQLITE_OK) {
          NSLog(@"Database Opened");
          // Attach empty encrypted database to unencrypted database
          sqlite3_exec(unencrypted_DB, "ATTACH DATABASE 'encrypted.db' AS encrypted KEY '1234';", NULL, NULL, NULL);
  
          // export database
          sqlite3_exec(unencrypted_DB, "SELECT sqlcipher_export('encrypted');", NULL, NULL, NULL);
  
          // Detach encrypted database
          sqlite3_exec(unencrypted_DB, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
  
          NSLog (@"End database copying");
          sqlite3_close(unencrypted_DB);
      }
      else {
          sqlite3_close(unencrypted_DB);
          NSAssert1(NO, @"Failed to open database with message '%s'.", sqlite3_errmsg(unencrypted_DB));
      }
  }
  </code></pre>
  
  <p>No issues running above, but encrypted.db is not appearing in my documents folder.</p>
  
  <p>After setting up the ssl and sqlcipher in my application. 
  Using this </p>
  
  <pre><code>- (void) openCipherDB
  {
      NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
                                stringByAppendingPathComponent: @"unencrypted.db"];
      NSLog(@"database path %@", databasePath);
      sqlite3 *db;
      if (sqlite3_open([databasePath UTF8String], &amp;db) == SQLITE_OK)
      {
          //sqlite3_exec(_db, "ATTACH DATABASE 'xyz.sqlite' AS encrypted KEY 'test';", NULL, NULL, &amp;t)
          const char* key = [@"secret" UTF8String];
          int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);       //i added this after seeing SO
          sqlite3_key(db, key, strlen(key));
          if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
              // password is correct, or, database has been initialized
              NSLog(@"database initialize");
          } 
          else 
          {
              NSLog(@"incorrect pass");
              // incorrect password!
          }
  
          sqlite3_close(db);
      }
  }
  </code></pre>
  
  <p>it gives me the NSLog of incorrect password and of course my db is not encrypted too. </p>
  
  <p>what else can i do to encrypt my db?
  thanks.</p>