bricke / Qt-AES

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

removePadding problem #18

Closed passy1977 closed 5 years ago

passy1977 commented 5 years ago

Hi, I think to find a problem in removePadding method.

below the code: QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC);


    QString inputStr("Carte di credito");
    QString key("test@test.it");
    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() << encodeText << "|" << decodeText << "|"<< decodedString;

this is the result:

"\x13\xE8\x1ES\x1Bv\xBF\xDCp\xF4i\xB7\xF2\xB0\xD1" | "Carte di credito" | ""_

the value of encodeText and decodeText I think are ok but decodedString is empty after removePadding assignment.

I don't know cryptography well and I don't know how to help you.

This code is tested on: MacBook Pro 2017, macOS 10.14 and QT 5.11.2

Thanks for the nice project

Bye

bricke commented 5 years ago

This may be because your "Carte di credito" is exacly 16 bytes, padding is not added and when removed it clears the string, I'll look into it, thanks!

bricke commented 5 years ago

Please check out SHA 3d4c882683e146c0b7665b6aad6f682b5c48f205

There was a PR that solves this issue, I also added a new test case based on a 16 byte string

passy1977 commented 5 years ago

Great! Now I try it. Thanks a lot