bricke / Qt-AES

Native Qt AES encryption class
The Unlicense
508 stars 187 forks source link

QAESEncryption Level is not working #63

Open tlhcelik opened 9 months ago

tlhcelik commented 9 months ago

I tried to AES_256, AES_192, AES_128 encryption levels with ECB, CBC, CFB, OFB modes.

AES_128 is not working AES_192 is not working AES_256 working

The output is empty byte array.

`

QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CFB);

QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael "
    "is a specification for the encryption of electronic data established by the U.S. "
    "National Institute of Standards and Technology (NIST) in 2001");
QString key("your-string-key");
QString iv("your-IV-vector");

QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);

QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);

QString decodedString = QString(encryption.removePadding(decodeText));
qDebug() <<"\n\nencodeText : " << encodeText << "\n\ndecodedString: " << decodedString;

`

What should I change in this code for properly working AES_128 and AES_192 ?

bricke commented 9 months ago

Hi, it's possible one of the recently merged changes broke the code, can you try with an older commit? Can you post a code sample that fails?

tlhcelik commented 9 months ago

I want to thank you for your fast response. I tried following code with AES_256 and this is working perfect. But when I change encryption level there is no any output. I built the QtAES.lib from master branch. ` void MainWindow::AES_TEST() { //TEST QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC);

QString inputStr("Ataturk dealt with the translation of scientific terminology into Turkish."
    "He wanted the Turkish language reform to be methodologically based."
    "Any attempt to cleansethe Turkish language of foreign influence without"
    "modelling the integral structure of the language was inherently wrong to him");
QString key("your-string-key");
QString iv("your-IV-vector");

QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);

QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);

QString decodedString = QString(encryption.removePadding(decodeText));
qDebug() << "\n\nencodeText : " << encodeText << "\n\ndecodedString: " << decodedString;

//TEST

} `

The output with AES_256: encodeText : "v\x1AzA\xD3\x96\xBA\xB2G\x89s\xE8\xF8\x07""6\xFA\x1F\x15[\x02\rpf\x86{>$\r*\x9D\xC1""1z\xE0\xF0\x13\xCC_A\xFD\x86W\xE4""7kpr\x11\x1C\x05Q\xD1\xA8\xE0;\xC1}|\x9F+)\x82""C\x06\x16:\xF9\x1B\xA7\xE2\xD2\xEB\xEE\xB9\x0E\x9E\x0B""A\x0B\xE6\xD1""EJQ\b\xA3\x19\x8D\x8F\x03\xC8\xFD\xD9@\xEC\xEA\xC6\x07N\xADZ9\x12\xF3\x9Em\xFE\xD5\xB9\xB2\x83\x94\x91\x02R\x03\xEBW\x99""f\xA5\xCE\xB4\xF8tF1RU\xB9\x0F\xED""E\xB3z\xB2K\xB1P\xCE\xBE""d\xF6\x8F\x07\xFC]\xD3\x80\xB9\xBE@\x9F""1G\n\x93""9JO\xBF\xDF\x89\xC6Kh!\x1D\xEE""Eh\x10$%~\xC2\xE4""1\brB\xD6\x82j\xF8\n\xA3\xA3J\x8Dl\x04W\xC8Z\x14\x0E\x19R|^\xB4M-\x91:\xC9\xD9\x10\xB8\x97""8P\xBD""A|\x95\xFE\xB2\x15\rm+\xC0""8<\xE3]z\xB1""3\x12\xD1j\xDB\x06\xA2\xD8=\x90gy\xDAy\xCA\xDD'\xFA\xD3\xCFy\x06!!\xC2\xDEj\x00\xE4\xA3|-s\xE1\r\x9Fn\xA1\x8B!\x18u\x9C\xD5\x15\xC4\x8D\xC6j\xF4\xCAYM\x19"

decodedString: "Ataturk dealt with the translation of scientific terminology into Turkish.He wanted the Turkish language reform to be methodologically based.Any attempt to cleansethe Turkish language of foreign influence withoutmodelling the integral structure of the language was inherently wrong to him"

The following code giving not any output:

` void MainWindow::AES_TEST() { //TEST QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC);

QString inputStr("Ataturk dealt with the translation of scientific terminology into Turkish."
    "He wanted the Turkish language reform to be methodologically based."
    "Any attempt to cleansethe Turkish language of foreign influence without"
    "modelling the integral structure of the language was inherently wrong to him");
QString key("your-string-key");
QString iv("your-IV-vector");

QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);

QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);

QString decodedString = QString(encryption.removePadding(decodeText));
qDebug() << "\n\nencodeText : " << encodeText << "\n\ndecodedString: " << decodedString;

//TEST

} ` The output with AES_128: encodeText : ""

decodedString: ""

bricke commented 9 months ago

I'll look into it