New SimpleCrypt page
Page |
5 |
Great job, easy to use. One question, I tested my app on Debian and Mint and no problem, but on Fedora 17 and Arch
I get “Invalid version or not a cyphertext.”
- char version = ba.at(0);
- if (version !=3) { //we only work with version 3
- m_lastError = ErrorUnknownVersion;
- qWarning() << "Invalid version or not a cyphertext.";
- }
Hi,
I have just added a page [developer.qt.nokia.com] in the Snippets category
Thanks for this class. I am invoking it’s constructor with my predefined key (my secret) and I am wondering why qsrand() is initialized with currentTimeMillis or similar (in the constructor code)? I don’t get the same encryption results on multiple invocations so I used my quint64 key to initialize qsrand (in the constructor), then it works..
- SimpleCrypt c1(Q_UINT64_C(0x0c2ad4a4acb9f023)); //some random number
- SimpleCrypt c2(Q_UINT64_C(0x0c2ad4a4acb9f023)); //some random number
Output
- Crypt1 "AwLLXV+ZSO+x3Ise1Aw="
- Crypt2 "AwIUgoBGlzBuA1TBC9M="
Just wondering :)
Why would you want to have the same cypher text when using the same clear text and key? As long as the decrypted plain text from these cypher texts is the same, what is the problem with having different cypher texts? The algorithm uses a randomization of the string on purpose. It makes it much harder to leak part of the key because analysis is much harder this way.
An explanation is in the details page that has more on the idea of using a random number as a leading byte.
You replacing that they way you did partly negates this, and thus makes the cypher weaker by a couple of bits. Note that even with your change, encrypting the same plain text using the same SimpleCrypt instance twice will result in different cypher texts.
Hi Andre,
Thanks for answering; I wasn’t looking for reasonably strong encryption – I just wanted to always get the same encrypted string for the same input (private key+string_to_be_encrypted); its just for private use anyway, and non-critical.
I am using QCryptographicHash for that now, it solves my problem
Eh, no, that class does not solve your problem, if you are indeed looking for encryption rather than hashing. There is a big difference between the two…
That’s a chicken and egg problem: I don’t want to elaborate on “my problem” and hence prove that I am fine with hashing because of concerns of privacy. Please understand that and thank you for your help.
good thing I changed was this:
- //QString cypherString = QString::fromAscii(cypher.toBase64());
- //QString cypherString = QString::fromAscii(cypher.toBase64());
- //QByteArray cyphertextArray = QByteArray::fromBase64(cyphertext.toAscii());
- //QByteArray cyphertextArray = QByteArray::fromBase64(cyphertext.toAscii());
there will be well done this.
You must log in to post a reply. Not a member yet? Register here!




