Example #1
0
/**
 * Returns decrypted note text if it is encrypted
 * The crypto key has to be set in the object
 */
QString Note::getDecryptedNoteText() {
    QString noteText = this->noteText;
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return noteText;
    }

    // decrypt the note text
    BotanWrapper botanWrapper;
    botanWrapper.setPassword(cryptoPassword);
    botanWrapper.setSalt(BOTAN_SALT);
    QString decryptedNoteText = botanWrapper.Decrypt(encryptedNoteText);

    // fallback to SimpleCrypt
    if (decryptedNoteText == "") {
        SimpleCrypt *crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
        decryptedNoteText = crypto->decryptToString(encryptedNoteText);
    }

    if (decryptedNoteText == "") {
        return noteText;
    }

    // get regular expression for the encrypted string
    QRegularExpression re = getEncryptedNoteTextRegularExpression();

    // replace the encrypted text with the decrypted text
    noteText.replace(re, decryptedNoteText);
    return noteText;
}
Example #2
0
/**
 * Encrypts the note text with the note's crypto key
 */
QString Note::encryptNoteText() {
    // split the text into a string list
    QStringList noteTextLines = this->noteText.split(
            QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"));

    // keep the first two lines unencrypted
    noteText = noteTextLines.at(0) + "\n" + noteTextLines.at(1) + "\n\n" +
               QString(NOTE_TEXT_ENCRYPTION_PRE_STRING) + "\n";

    // remove the first two lines for encryption
    noteTextLines.removeFirst();
    noteTextLines.removeFirst();

    // remove the 3rd line too if it is empty
    if (noteTextLines.at(0) == "") {
        noteTextLines.removeFirst();
    }

    // join the remaining lines
    QString text = noteTextLines.join("\n");

    // empty notes will be detected as "can't be decrypted",
    // so we will add a space
    if (text.isEmpty()) {
        text = " ";
    }

    // encrypt the text
    BotanWrapper botanWrapper;
    botanWrapper.setPassword(cryptoPassword);
    botanWrapper.setSalt(BOTAN_SALT);
    QString encryptedText = botanWrapper.Encrypt(text);

//    SimpleCrypt *crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
//    QString encryptedText = crypto->encryptToString(text);

    // add the encrypted text to the new note text
    noteText += encryptedText + "\n" +
                QString(NOTE_TEXT_ENCRYPTION_POST_STRING);

    // store note
    store();

    return noteText;
}
Example #3
0
/**
 * Checks if note text can be decrypted
 */
bool Note::canDecryptNoteText() {
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return false;
    }

    // decrypt the note text
    BotanWrapper botanWrapper;
    botanWrapper.setPassword(cryptoPassword);
    botanWrapper.setSalt(BOTAN_SALT);
    QString decryptedNoteText = botanWrapper.Decrypt(encryptedNoteText);

    // fallback to SimpleCrypt
    if (decryptedNoteText == "") {
        SimpleCrypt *crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
        decryptedNoteText = crypto->decryptToString(encryptedNoteText);
    }

    return decryptedNoteText != "";
}
Example #4
0
void Krypta::Decrypt(){
    if (globFile == "" || ui->txtFileChosen->text() == ""){
        QMessageBox msgBox;
        msgBox.setText("Error!");
        msgBox.setInformativeText("Please choose a file to decrypt!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
    } else if (!globFile.endsWith(".Krypt")){
        QMessageBox msgBox;
        msgBox.setText("File not encrypted");
        msgBox.setInformativeText("The File is not encrypted & therefore doesn't need decrypting!\nPlease choose a file that has been encrypted by this program!\nFiles encrypted with this program will bear the .Krypt extension!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
    } else if (ui->txtPass->text() == ""){
        QMessageBox msgBox;
        msgBox.setText("Error");
        msgBox.setInformativeText("Please enter a password!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
        this->Clear();
    } else if (globFile.endsWith(".KryptV")){
        QMessageBox msgBox;
        msgBox.setText("Encrypted Volume File!");
        msgBox.setInformativeText("This File is an encrypted volume! Please encrypt/decrypt volumes by clicking the Volumes button.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
        this->Clear();
    } else if (globFile == globKeyFile){
        QMessageBox msgBox;
        msgBox.setText("Error");
        msgBox.setInformativeText("The file to be decrypted cannot be used as a keyfile!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
        this->Clear();
    } else{

    if(ui->chk1Pass->isChecked() && ui->chkKeyfile->isChecked()){
        if (globKeyFile == "" || ui->txtKeyfile->text() == ""){
            QMessageBox msgBox;
            msgBox.setText("No Keyfile");
            msgBox.setInformativeText("Please choose a keyfile!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            msgBox.exec();
            this->Clear();
        } else{

        QString fileName = QFileDialog::getSaveFileName(this, "Save a file", "", "Any (*.*)");


        BotanWrapper cWrapper;

        QString cEncrypted = globFile;
        QString cDecrypted = fileName;

        QString hashedPassword = (ui->txtPass->text() + globKeyFile);
        QString skein512 = QSkeinHash(hashedPassword, QSkeinHash::hb512).toHexString();
                cWrapper.setPassword(skein512);
                cWrapper.setPassword2(skein512);
                cWrapper.setPassword3(skein512);


        cWrapper.DecryptFile(cEncrypted, cDecrypted);

        if(ui->chkDelOrig->isChecked()){
            QFile orig(globFile);
            orig.remove();
        }
        this->Clear();

        }
    } else if (ui->chk1Pass->isChecked() && !ui->chkKeyfile->isChecked()){
        QString fileName = QFileDialog::getSaveFileName(this, "Save a file", "", "Any (*.*)");


        BotanWrapper cWrapper;

        QString cEncrypted = globFile;
        QString cDecrypted = fileName;

        cWrapper.setPassword(ui->txtPass->text());
        cWrapper.setPassword2(ui->txtPass->text());
        cWrapper.setPassword3(ui->txtPass->text());


        cWrapper.DecryptFile(cEncrypted, cDecrypted);

        if(ui->chkDelOrig->isChecked()){
            QFile orig(globFile);
            orig.remove();
        }
        this->Clear();

    } else if (ui->chkKeyfile->isChecked() && !ui->chk1Pass->isChecked()){
        if (globKeyFile == "" || ui->txtKeyfile->text() == ""){
            QMessageBox msgBox;
            msgBox.setText("No Keyfile");
            msgBox.setInformativeText("Please choose a keyfile!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            msgBox.exec();
            this->Clear();
        } else if (ui->txtPass2->text() == "" || ui->txtPass3->text() == ""){
            QMessageBox msgBox;
            msgBox.setText("Missing Password(s)");
            msgBox.setInformativeText("Please enter a second and/or third password!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            msgBox.exec();
            this->Clear();
        } else{

        QString fileName = QFileDialog::getSaveFileName(this, "Save a file", "", "Any (*.*)");//globFile.replace(QString(".Krypt"), QString(""))



        BotanWrapper cWrapper;

        QString cEncrypted = globFile;
        QString cDecrypted = fileName;

        QString hashedPassword1 = (ui->txtPass->text() + globKeyFile);
        QString hashedPassword2 = (ui->txtPass2->text() + globKeyFile);
        QString hashedPassword3 = (ui->txtPass3->text() + globKeyFile);
        QString skein5121 = QSkeinHash(hashedPassword1, QSkeinHash::hb512).toHexString();
        QString skein5122 = QSkeinHash(hashedPassword2, QSkeinHash::hb512).toHexString();
        QString skein5123 = QSkeinHash(hashedPassword3, QSkeinHash::hb512).toHexString();
                cWrapper.setPassword(skein5121);
                cWrapper.setPassword2(skein5122);
                cWrapper.setPassword3(skein5123);


        cWrapper.DecryptFile(cEncrypted, cDecrypted);

        if(ui->chkDelOrig->isChecked()){
            QFile orig(globFile);
            orig.remove();
        }
        this->Clear();

        }
    } else{
        if(ui->txtPass2->text() == "" || ui->txtPass3->text() == ""){
            QMessageBox msgBox;
            msgBox.setText("Missing Password(s)");
            msgBox.setInformativeText("Please enter a second and/or third password!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            msgBox.exec();
            this->Clear();
        } else{
    QString fileName = QFileDialog::getSaveFileName(this, "Save a file", "", "Any (*.*)");


    BotanWrapper cWrapper;

    QString cEncrypted = globFile;
    QString cDecrypted = fileName;

    cWrapper.setPassword(ui->txtPass->text());
    cWrapper.setPassword2(ui->txtPass2->text());
    cWrapper.setPassword3(ui->txtPass3->text());


    cWrapper.DecryptFile(cEncrypted, cDecrypted);

    if(ui->chkDelOrig->isChecked()){
        QFile orig(globFile);
        orig.remove();
    }
    this->Clear();

      }
    }
  }
}
Example #5
0
void ExtractVolume::ExtractVol(){
    QString ZipFile = globFile;
    qDebug() << ZipFile;
    if(ZipFile.endsWith(".KryptV")){
        if (ui->txtPass1->text() == ""){
            QMessageBox msgBox;
            msgBox.setText("Error");
           // msgBox.setIcon();
            msgBox.setInformativeText("Please enter a password!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox.exec();
           // return 0;
            this->Clear();
        } else if(!ui->chk1Pass->isChecked() && (ui->txtPass2->text() == "" || ui->txtPass3->text() == "")){
            QMessageBox msgBox;
            msgBox.setText("Missing Password(s)");
           // msgBox.setIcon();
            msgBox.setInformativeText("Please enter a second and/or third password!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox.exec();
            //return 0;
            this->Clear();
        } else{

            if (ui->chk1Pass->isChecked() && ui->chkUseKeyfile->isChecked()){
                QString NewDir = QFileDialog::getSaveFileName(this, "Save the extracted volume", "", "Any (*.*)");
                QFileInfo name = NewDir;
                QString base = name.baseName();
                QString tempZip = dir + "/" + base + ".zip";


                BotanWrapper cWrapper;

                QString hashedPassword = (ui->txtPass1->text() + globKeyFile);
                QString skein512 = QSkeinHash(hashedPassword, QSkeinHash::hb512).toHexString();
                        cWrapper.setPassword(skein512);
                        cWrapper.setPassword2(skein512);
                        cWrapper.setPassword3(skein512);


                cWrapper.DecryptFile(ZipFile, tempZip);

                //List the contents of a zip file
                ListContents(tempZip);


                //Decompress an archive to a directory
                DecompressDir(tempZip,NewDir);

QFile elIF(tempZip);
elIF.remove();

            QMessageBox msgBox;
            msgBox.setText("Success!");
           // msgBox.setIcon();
            msgBox.setInformativeText("Volume successfully extracted!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox.exec();
            //return 0;
            this->Clear();
            } else if(ui->chk1Pass->isChecked() && !ui->chkUseKeyfile->isChecked()){
                QString NewDir = QFileDialog::getSaveFileName(this, "Save the extracted volume", "", "Any (*.*)");
                QFileInfo name = NewDir;
                QString base = name.baseName();
                QString tempZip = dir + "/" + base + ".zip";


                BotanWrapper cWrapper;
                cWrapper.setPassword(ui->txtPass1->text());
                cWrapper.setPassword2(ui->txtPass1->text());
                cWrapper.setPassword3(ui->txtPass1->text());


                cWrapper.DecryptFile(ZipFile, tempZip);

                //List the contents of a zip file
                ListContents(tempZip);


                //Decompress an archive to a directory
                DecompressDir(tempZip,NewDir);

QFile elIF(tempZip);
elIF.remove();

            QMessageBox msgBox;
            msgBox.setText("Success!");
           // msgBox.setIcon();
            msgBox.setInformativeText("Volume successfully extracted!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox.exec();
            //return 0;
            this->Clear();
            } else if(ui->chkUseKeyfile->isChecked() && !ui->chk1Pass->isChecked()){
                QString NewDir = QFileDialog::getSaveFileName(this, "Save the extracted volume", "", "Any (*.*)");
                QFileInfo name = NewDir;
                QString base = name.baseName();
                QString tempZip = dir + "/" + base + ".zip";


                BotanWrapper cWrapper;

                QString hashedPassword = (ui->txtPass1->text() + globKeyFile);
                QString hashedPassword2 = (ui->txtPass2->text() + globKeyFile);
                QString hashedPassword3 = (ui->txtPass3->text() + globKeyFile);
                QString skein512 = QSkeinHash(hashedPassword, QSkeinHash::hb512).toHexString();
                QString skein5122 = QSkeinHash(hashedPassword2, QSkeinHash::hb512).toHexString();
                QString skein5123 = QSkeinHash(hashedPassword3, QSkeinHash::hb512).toHexString();
                        cWrapper.setPassword(skein512);
                        cWrapper.setPassword2(skein5122);
                        cWrapper.setPassword3(skein5123);


                cWrapper.DecryptFile(ZipFile, tempZip);

                //List the contents of a zip file
                ListContents(tempZip);


                //Decompress an archive to a directory
                DecompressDir(tempZip,NewDir);

QFile elIF(tempZip);
elIF.remove();

            QMessageBox msgBox;
            msgBox.setText("Success!");
           // msgBox.setIcon();
            msgBox.setInformativeText("Volume successfully extracted!");
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.setDefaultButton(QMessageBox::Ok);
            int ret = msgBox.exec();
            //return 0;
            this->Clear();
            } else{

        QString NewDir = QFileDialog::getSaveFileName(this, "Save the extracted volume", "", "Any (*.*)");
        QFileInfo name = NewDir;
        QString base = name.baseName();
        QString tempZip = dir + "/" + base + ".zip";


        BotanWrapper cWrapper;
        cWrapper.setPassword(ui->txtPass1->text());
        cWrapper.setPassword2(ui->txtPass2->text());
        cWrapper.setPassword3(ui->txtPass3->text());


        cWrapper.DecryptFile(ZipFile, tempZip);

        //List the contents of a zip file
        ListContents(tempZip);


        //Decompress an archive to a directory
        DecompressDir(tempZip,NewDir);

QFile elIF(tempZip);
elIF.remove();

    QMessageBox msgBox;
    msgBox.setText("Success!");
   // msgBox.setIcon();
    msgBox.setInformativeText("Volume successfully extracted!");
    msgBox.setStandardButtons(QMessageBox::Ok);
    msgBox.setDefaultButton(QMessageBox::Ok);
    int ret = msgBox.exec();
    //return 0;
    this->Clear();
            }}} else{
        QMessageBox msgBox;
        msgBox.setText("Error!");
       // msgBox.setIcon();
        msgBox.setInformativeText("The selected file is not a volume created with this program and cannot\n be extracted.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        int ret = msgBox.exec();
        //return 0;
        this->Clear();
    }

}