On 06.04.2011 14:21, Ulric Auger wrote:
> Hi,
>
> I think I found a bug creating an encrypted backup.

..

>
>
>
> When I use the following function to create a backup of the database, the
> backup database becomes unreadable.

...
>
>
>
>    rc = sqlite3_open(zFilename,&pBackupDb);
>
>    if( rc==SQLITE_OK )
>
>    {
>
>      if (zKey != NULL)
>
>          sqlite3_key(pBackupDb, zKey, strlen(zKey));

I can't recall why but when you create a new DB you need to call
sqlite3_key twice. Try making it:
if (zKey != NULL)
{
    sqlite3_key(pBackupDb, NULL, 0);
    sqlite3_key(pBackupDb, zKey, strlen(zKey));
}

However, I'm surprised to see that the backup API doesn't
create an exact copy of the source DB when SEE is involved.
I tend to argue that a backup should be encrypted automatically
if the source DB uses SEE as well. In my case I generated some
nice backup DBs which are now not encrypted at the customers side.
Sigh...

Anyway, hope this helps.

Marcus


>
>
>
>      pBackup = sqlite3_backup_init(pBackupDb, "main", pDb, "main");
>
>      if( pBackup )
>
>      {
>
>        do
>
>        {
>
>          rc = sqlite3_backup_step(pBackup, 100);
>
>          if( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
>
>            sqlite3_sleep(10);
>
>          }
>
>        }
>
>        while( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED );
>
>
>
>        sqlite3_backup_finish(pBackup);
>
>      }
>
>      rc = sqlite3_errcode(pBackupDb);
>
>    }
>
>
>
>    sqlite3_close(pBackupDb);
>
>    return rc;
>
> }
>
>
>
> Ulric Auger
> --
> Groupe Techna Inc.
>   <mailto:ul...@gtechna.com>  ul...@gtechna.com
>
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to