Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encrypt existing database #603

Open
zeeshan-i-pathan opened this issue Apr 30, 2015 · 0 comments
Open

Encrypt existing database #603

zeeshan-i-pathan opened this issue Apr 30, 2015 · 0 comments
Assignees

Comments

@zeeshan-i-pathan
Copy link

If i try to encrypt an existing database it gets corrupted and gives the file is encrypted or is not a database error is there no export feature for this case. I tried modifying the code to something like.

   // for opening the database
    boolean bExist;
    boolean encrypted;
    int nRes;
      if( CRhoFile::isFileExist(strDbPath.c_str()) && checkImportState) {
        encrypted = false;
        bExist = CRhoFile::isFileExist((strDbPath).c_str());
        nRes = sqlite3_open((strDbPath).c_str(),&m_dbHandle);
        LOG(INFO)+"Opening without encryption";
      } else {
        encrypted = true;
        bExist = CRhoFile::isFileExist((strDbPath+"_enc").c_str());
        nRes = sqlite3_open((strDbPath+"_enc").c_str(),&m_dbHandle);
        LOG(INFO)+"Opening with encrypted";
      }

   // for the PRAGMA call
    if ( szEncrypt && strcmp(szEncrypt, "1") == 0 && encrypted)

  // and finally after all that 
    if( !encrypted )
    {
      String strCreate = "select name from sqlite_master where type='table' and name!='sqlite_seqeunce' and rootpage>0;";
      IDBResult res = executeSQL( strCreate.c_str() );
      CDBAdapter db(m_strDbPartition.c_str(), true);
      // this db opens with the pragma call as i have put logs there to be sure
      db.open( strDbPath, m_strDbVer, true, false ); 
      db.startTransaction(); # all this also works fine 
      for ( ; !res.isEnd(); res.next() ) {
        String createTableStatement = res.getStringByIdx(0);
        LOG(INFO)+"copying table "+createTableStatement;
        copyTable( createTableStatement, *this, db );
      }
      db.endTransaction();
      db.close();
      close(false);
      CRhoFile::deleteFile(strDbPath.c_str());
      // here the strDbPath_enc database that is opened still gives the file is encrypted or not a database error.
      open( strDbPath, m_strDbVer, false, false ); 
    }
@alex-epifanoff alex-epifanoff self-assigned this Nov 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants