You should be setting they key on the database (if it’s encrypted) prior to running any operations on it (i.e. cipher_plaintext_header_size).
Step 3: sqlite3_exec(db, (const char*) [@“databaseKey” UTF8String], NULL, NULL, NULL)
There are examples here of how to set the key, the syntax above doesn’t look like you’re using one of those (i.e. PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";)
You may want to review the cipher_plaintext_header_size documentation. As noted there, the application is responsible for providing the salt as well when using cipher_plaintext_header.