/** * 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; }
/** * Returns encrypted note text if it is encrypted */ QString Note::getEncryptedNoteText() { QString noteText = this->noteText; // get regular expression for the encrypted string QRegularExpression re = getEncryptedNoteTextRegularExpression(); // check if we have an encrypted note text and return it if so QRegularExpressionMatch match = re.match(noteText); return match.hasMatch() ? match.captured(1) : ""; }
/** * 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 SimpleCrypt* crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey)); QString 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; }