带结果保存的Blowfish加密/解密(Qt-qblowfish)
当我同时保存时,如何恢复我从河豚成功加密中获得的密码文本带结果保存的Blowfish加密/解密(Qt-qblowfish),qt,encryption,blowfish,Qt,Encryption,Blowfish,当我同时保存时,如何恢复我从河豚成功加密中获得的密码文本 secretKey是关键字的哈希值 QString clearText(textBrowser->toHtml()); QBlowfish bf(secretKey); bf.setPaddingEnabled(true); QByteArray encryptedBa = bf.encrypted(clearText.toUtf8()); // I want to save the encrypted text in a
secretKey
是关键字的哈希值
QString clearText(textBrowser->toHtml());
QBlowfish bf(secretKey);
bf.setPaddingEnabled(true);
QByteArray encryptedBa = bf.encrypted(clearText.toUtf8());
// I want to save the encrypted text in a file to store it.
// Here I am "emulating" this intent:
// I am saving with flushing an outStream, I convert it to QString before:
QString test_SavedText(encryptedBa); //This value gets saved
QString cryptedText(test_SavedText); //"Read the stored file"
QByteArray decryptedBa = bf.decrypted(cryptedText.toUtf8());
encryptedBa
正在工作。如果我直接将它插入到我的解密的
-调用中,它将被解密。
但是,当我使用我的cryptedText.toUtf8()
调用解密时,它不起作用
一些调试显示:QString需要填充。好的,在解密方法中,我在它的
QByteArray
中添加了填充(与加密的方式完全相同)。但是我的decryptedBa
-输出仍然是空的。我仍然不明白为什么我的QString需要填充-它不是由QByteArray制作的吗?它已经包括填充了吗?我意识到现在是你问这个问题的时候了,但我刚刚偶然发现,你不想在加密数据上使用.toUtf8(),而是,在解密后的结果上这段代码对我有效
QString enc(QString data) {
QBlowfish bf(QString("This is The key").toUtf8());
bf.setPaddingEnabled(true);
QByteArray cipherText = bf.encrypted(data.toUtf8());
return QString(cipherText.toHex());
}
QString dec(QString enc_data) {
QBlowfish bf(QString("This is The key").toUtf8());
bf.setPaddingEnabled(true);
QByteArray decryptedBa = bf.decrypted(QByteArray::fromHex(enc_data.toUtf8()));
return QString::fromUtf8(decryptedBa.constData(), decryptedBa.size());
}