Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

fixed grammar
Source Link
JaMiT
  • 18.7k
  • 5
  • 20
  • 44

I need sqlcipher verSQLCipher version 4.x for my cppC++ project. I do have sqlcipherSQLCipher 4.6.0 Community in my ubuntuUbuntu, but it showshows 3.4.1 in my cppC++ program. I have tried to compile and use sqlcipherSQLCipher 4.6.0 and 4.6.1 for compilecompiling my source code, but it just givegives me athe same result.

I do tried to deal with sqlciphera SQLCipher 3 (HMAC_SHA1) encrypted database and it works! BUT I do need to deal with some database which encryptencrypts with sqlcipherSQLCipher 4 (HMAC_SHA512)。

My target is that my cppC++ program should work with SQLCipher 4.6.0 community, and successful query the encrypted database.

I need sqlcipher ver 4.x for my cpp project. I do have sqlcipher 4.6.0 Community in my ubuntu, but it show 3.4.1 in my cpp program. I have tried compile and use sqlcipher 4.6.0 and 4.6.1 for compile my source code, but it just give me a same result.

I do tried deal with sqlcipher 3 (HMAC_SHA1) encrypted database and it works! BUT I do need to deal with some database which encrypt with sqlcipher 4 (HMAC_SHA512)。

My target is my cpp program should work with SQLCipher 4.6.0 community, and successful query the encrypted database.

I need SQLCipher version 4.x for my C++ project. I do have SQLCipher 4.6.0 Community in my Ubuntu, but it shows 3.4.1 in my C++ program. I have tried to compile and use SQLCipher 4.6.0 and 4.6.1 for compiling my source code, but it just gives me the same result.

I tried to deal with a SQLCipher 3 (HMAC_SHA1) encrypted database and it works! BUT I do need to deal with some database which encrypts with SQLCipher 4 (HMAC_SHA512)。

My target is that my C++ program should work with SQLCipher 4.6.0 community and successful query the encrypted database.

Source Link

SQLCipher C++ API version

I need sqlcipher ver 4.x for my cpp project. I do have sqlcipher 4.6.0 Community in my ubuntu, but it show 3.4.1 in my cpp program. I have tried compile and use sqlcipher 4.6.0 and 4.6.1 for compile my source code, but it just give me a same result.

I do tried deal with sqlcipher 3 (HMAC_SHA1) encrypted database and it works! BUT I do need to deal with some database which encrypt with sqlcipher 4 (HMAC_SHA512)。

My target is my cpp program should work with SQLCipher 4.6.0 community, and successful query the encrypted database.

Source code:

#define DSQLITE_HAS_CODEC = 1
#include <iostream>
#include <sqlcipher/sqlite3.h>
using namespace std;
void executeSQL(sqlite3* db, const char* sql) 
{
 char* errMsg = nullptr;
 int rc = sqlite3_exec(db, sql, nullptr, nullptr, &errMsg);
 
 cout << "SQL CMD: " << sql << endl;
 
 if (rc != SQLITE_OK) 
 {
 cerr << "SQL error: " << errMsg << endl;
 sqlite3_free(errMsg);
 } 
 else 
 {
 cout << "SQL command executed successfully." << endl;
 }
}
int main() {
 sqlite3 *db;
 sqlite3_stmt *stmt;
 int rc;
 
 rc = sqlite3_open("enc_Dev.db", &db);
 const char *sql_cipher_key = "PRAGMA key = '<64-byte key>';";
 executeSQL(db, sql_cipher_key);
 
 const char *sql_cipher_ver = "PRAGMA cipher_default_compatibility = 4;";
 executeSQL(db, sql_cipher_ver);
 const char *sql_cipher_page_size = "PRAGMA cipher_page_size = 4096;";
 executeSQL(db, sql_cipher_page_size);
 const char *sql_cipher_kdf_iter = "PRAGMA kdf_iter = 256000;";
 executeSQL(db, sql_cipher_kdf_iter);
 
 const char *sql_cipher_hmac_algo = "PRAGMA cipher_hmac_algorithm = HMAC_SHA512;";
 executeSQL(db, sql_cipher_hmac_algo);
 
 const char *sql_cipher_kdf_algo = "PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;";
 executeSQL(db, sql_cipher_kdf_algo);
 
 const char *sql_cipher_pt_hsize = "PRAGMA cipher_plaintext_header_size = 0;";
 executeSQL(db, sql_cipher_pt_hsize);
 if (sqlite3_exec(db, "SELECT count(*) FROM input_records;", NULL, NULL, NULL) != SQLITE_OK)
 {
 cerr << "Open encrypted database fail!" << endl;
 }
 const char *sql_ck = "PRAGMA cipher_version;";
 rc = sqlite3_prepare_v2(db, sql_ck, -1, &stmt, 0);
 int i = 0;
 while (sqlite3_step(stmt) == SQLITE_ROW) 
 {
 const unsigned char *output = sqlite3_column_text(stmt, i);
 cout << "PRAGMA cipher_version;\nResult: " << output;
 i++;
 }
 cout <<endl;
 const char *sql_prvdck = "PRAGMA cipher_provider_version;";
 rc = sqlite3_prepare_v2(db, sql_prvdck, -1, &stmt, 0);
 i = 0;
 while (sqlite3_step(stmt) == SQLITE_ROW)
 {
 const unsigned char *output = sqlite3_column_text(stmt, i);
 cout << "PRAGMA cipher_provider_version;\nResult: " << output;
 i++;
 }
 cout <<endl;
 sqlite3_finalize(stmt);
 sqlite3_close(db);
 return 0;
}

Output:

SQL CMD: PRAGMA key = '<64-byte key>';
SQL command executed successfully.
SQL CMD: PRAGMA cipher_default_compatibility = 4;
SQL command executed successfully.
SQL CMD: PRAGMA cipher_page_size = 4096;
SQL command executed successfully.
SQL CMD: PRAGMA kdf_iter = 256000;
SQL command executed successfully.
SQL CMD: PRAGMA cipher_hmac_algorithm = HMAC_SHA512;
SQL command executed successfully.
SQL CMD: PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;
SQL command executed successfully.
SQL CMD: PRAGMA cipher_plaintext_header_size = 0;
SQL command executed successfully.
Open encrypted database fail!
PRAGMA cipher_version;
Result: 3.4.1
PRAGMA cipher_provider_version;
Result: OpenSSL 3.0.0 7 sep 2021

My Ubuntu SQLCipher version:

SQLite version 3.45.3 2024年04月15日 13:34:05 (SQLCipher 4.6.0 community)
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /