Here what I have got:
Question: how can I simply crypt and encrypt simple QString value? I need this to be able to save some crypted string into the INI file, and after reopening application encrypt string to normal password string value.
PS: I'm looking simple and nice solution.
Thanks for help!
Decryption Approach:Find the length L of the string. Find the ceil and floor values of √Length and assign them to the variables. Create a 2D matrix and fill the matrix by characters of string column-wise. Read the matrix row-wise to get the decrypted string.
On the File tab, click Info, and then click Encrypt with Password. The Set Database Password dialog box appears. Type your password in the Password box, type it again in the Verify box, and then click OK.
There is SimpleCrypt here: https://wiki.qt.io/Simple_encryption_with_SimpleCrypt and as the name suggests the author says that the class does not provide strong encryption but its pretty good in my view.
You can download a working example here: http://www.qtcentre.org/threads/45346-Encrypting-an-existing-sqlite-database-in-sqlcipher?p=206406#post206406
#include <QtGui>
#include "simplecrypt.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString FreeTrialStartDate ;
//Set The Encryption And Decryption Key
SimpleCrypt processSimpleCrypt(89473829);
QString FreeTrialStartsOn("22/11/2011");
//Encrypt
FreeTrialStartDate = processSimpleCrypt.encryptToString(FreeTrialStartsOn);
qDebug() << "Encrypted 22/11/2011 to" << FreeTrialStartDate;
//Decrypt
QString decrypt = processSimpleCrypt.decryptToString(FreeTrialStartDate);
qDebug() << "Decrypted 22/11/2011 to" << decrypt;
return a.exec();
}
If you just want to use it for as password, use a QCryptographicHash
. Hash the password, save it to the file. Then when you want to compare, hash the input and compare it to the saved password. Of course this is not very secure, and you can get into things like salting for increased security.
If you just want to be able to encrypt and decrypt a string that is stored in a file, use a cipher. Take a look at Botan or Crypto++.
This of course all depends on the levels of security you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With