# KDF iterations not changing in SQLCipher when creating a new database and exporting data

**URL:** <https://discuss.zetetic.net/t/kdf-iterations-not-changing-in-sqlcipher-when-creating-a-new-database-and-exporting-data/5917>\
**Category:** Issues\
**Created:** [May 4, 2023, 1:25am UTC](https://discuss.zetetic.net/t/kdf-iterations-not-changing-in-sqlcipher-when-creating-a-new-database-and-exporting-data/5917 "2023-05-04T01:25:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/user1/32/1989_2.png) [@user1](https://discuss.zetetic.net/u/user1)\
**Post date:** [May 4, 2023, 1:25am UTC](https://discuss.zetetic.net/t/kdf-iterations-not-changing-in-sqlcipher-when-creating-a-new-database-and-exporting-data/5917/1 "2023-05-04T01:25:45Z")

</div>

Hi all,

I am trying to export data from a plain SQLite database to an encrypted SQLCipher database with a specified number of KDF iterations. I have created an empty encrypted database and attached it to the plain database using the following code:

```auto
QString dbPathNameEnc = "databases/en.db";
QSqlDatabase encryptedDb = QSqlDatabase::addDatabase("SQLITECIPHER", "en");
encryptedDb.setDatabaseName(dbPathNameEnc);

if (!encryptedDb.open()) {
    qDebug() << "en not open";
    return false;
}

if(!password.isEmpty())
{
    QSqlQuery encquery(QSqlDatabase::database("en"));
    if(!encquery.exec("pragma key = '" + password +"';"))
    {
        qDebug() << "can't set password en";
        return false;
    }

    QSqlQuery kdfquery(QSqlDatabase::database("en"));
    if(!kdfquery.exec("PRAGMA kdf_iter = '10000';"))
    {
        qDebug() << "can't set kdf_iter";
        return false;
    }
}

QSqlQuery attachQuery(QSqlDatabase::database(currentUser));
if (!attachQuery.exec("ATTACH DATABASE '" + dbPathNameEnc + "' AS en KEY '" + password + "';"))
{
    qDebug() << "attach failed: " << attachQuery.lastError().text();
    return false;
}

QSqlQuery exportQuery(QSqlDatabase::database(currentUser));
if (!exportQuery.exec("SELECT sqlcipher_export('en');"))
{
    qDebug() << "export failed: " << exportQuery.lastError().text();
    return false;
}

```

After that I disable the encrypted database and close the normal database.  
When I check an encrypted database using DB Browser, the program does not require changing the number of iterations, and the default value of 256000 is used. I cannot set more than 10000, the application freezes if the value is large. If I later programmatically log in to this database with a value of 10000 iterations, then the database will not open. But at a value of 256000, it opens. That is, you cannot change iterations in an empty database? Can anyone suggest what might be causing this issue?

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/user1/32/1989_2.png) [@user1](https://discuss.zetetic.net/u/user1)\
**Post date:** [May 5, 2023, 12:44pm UTC](https://discuss.zetetic.net/t/kdf-iterations-not-changing-in-sqlcipher-when-creating-a-new-database-and-exporting-data/5917/2 "2023-05-05T12:44:26Z")

</div>

i solved the problem with this

> [@ATTACH on encrypted DB returning SQLITE\_NOTADB](https://discuss.zetetic.net/t/attach-on-encrypted-db-returning-sqlite-notadb/4137):
>
> I’m having a strange issue when trying to attach an encrypted database. Using SQLite 3.28.0 with SQLCipher v4.2.0. First I open up a database with the following commands: sqlite3\_open\_v2("database1.db", ...); sqlite3\_exec(..., "PRAGMA key = 'password'; PRAGMA kdf\_iter= 128000;", nullptr, nullptr, nullptr); Everything is fine up to this point. Now I try to attach another encrypted database: sqlite3\_exec(..., "ATTACH DATABASE 'c:/path/to/database2.db' AS db2 KEY 'password'; PRAGMA db2.kdf\_it…
