/** * 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; }
/** * 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 != ""; }