bricke / qt-aes Goto Github PK
View Code? Open in Web Editor NEWNative Qt AES encryption class
License: The Unlicense
Native Qt AES encryption class
License: The Unlicense
i tried using one of your examples and it crashes
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
ASSERT: "uint(i) < uint(size())" in file C:/Qt/Qt5.11.0/5.11.0/mingw53_32/include/QtCore/qbytearray.h, line 474
I'm using windows 7
qt 5.11.0
Hey,
Qt-AES is almost perfect and very easy to use and integrate, which makes it standout from the competition, so in this light can you expand beyond Qt-AES, and create similar encryption classes for the other four AES finalists?
My suggestion is first to expand and create:
Qt-MARS
Qt-RC6
Qt-Serpent
Qt-Twofish
And maybe, (as a hashing function) who knows:
Qt-Whirlpool
Let me know what do you think.
Hi
I am trying to decrypt data that encrypted with (php openssl) with AES_256 - CBC
the IV is = QByteArray iv = "0000000000000000";
the first section of the data is corrupted and the last is good
what is the problem and how to solve it ?
let me know if you need more info
Hi,
In pkcs # 7 padding,
If the size of the raw text is divided by the block size, should the raw text be padded to the size of the block size?
If you divide by block size, you are not padding.
(in getPadding (), if size == 0, return QByteArray ())
https://github.com/bricke/Qt-AES/blob/master/qaesencryption.cpp#L37
If 0x80
is not found in ret
, then -1
is passed to truncate(..)
which results in ret
being emptied.
Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
Please I have a problem in Qt-AES library, when I encrypt text multiple times in the same app, I get a text encrypted with less characters, and when I desencrypt in other app not desencrypt it.
Hi
In AES-CFB is there anyway to encode data without padding in the Qt-AES library?
I used QAESEncryption::ZERO
and QAESEncryption::ISO
but it still changes the encrypted data length
Thanks
Hi,
Does anyone know if Qt-AES is supporting the usage of protocol buffers (protobuf) ?
Because I tried to encode and decode a QByteArray with protobuf data and after decoding it's unable to retrieve the correct information.
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 ?
Hi, im using your source in my project and installing the app in Android 7.
THe code crash with this error:
A/MyApp: ASSERT: "uint(i) < uint(size())" in file C:\Qt\5.13.2\android_armv7\include\QtCore/qbytearray.h, line 481
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 28083 (qtMainLoopThrea)
Doing a lot of Debugging I arrived in expandedKey method:
row 218-> QByteArray roundKey(key); //The size of this element is 15
row 222-> m_nk = 4, m_nb = 4, m_nr = 10
for(i = m_nk; i < m_nb * (m_nr + 1); i++) { tempa[0] = (quint8) roundKey.at((i-1) * 4 + 0); tempa[1] = (quint8) roundKey.at((i-1) * 4 + 1); tempa[2] = (quint8) roundKey.at((i-1) * 4 + 2); tempa[3] = (quint8) roundKey.at((i-1) * 4 + 3);
When the code reach tempa[3] at row 227 with roundKey.at(), It tries to access the 15 element and goes into FATAL because the first loop is i = 4 so => (4-1) * 4 + 3 = 15 and roundKey last index is 14.
What can I do? I always use your class with my Android 9-10 and have no problem at all. Today I broke my phone and I used an old one and get this drama.
Hope my LOG can help you understand the problem, let me know as soon as you can
E:\Code_Qt\Qt-AES-master\qaesencryption.cpp:37: error: 'class QByteArray' has no member named 'back'
ret.remove(ret.length() - ret.back(), ret.back());
^
Does this library support file enc/decryption ?
hi ,
can you add PKCS#5 padding to this project ?
I use AES_128 for encoding. After encoding, I want to store the ciphertext to the Sqlite DB. To tackle this, I need to convert the qbytearray to qstring. I tried all possible way on the web but the output of the convertors are not the same as the qbytearray.
Is there any other option for me? Foe example is other encoding better than AES_128 for my purpose? Or other option for converting to QString?
I enabled the decryption methods in the aesni.h files and used the code from #if USE_INTEL_AESNI_IF_AVAILABLE from the encoding step for the decode method, so that I can feed AES_ECV_decrypt() with the right parameters. Unfortunately though, the computed data isn't the decrypted version of my encrypted original data.
Anyone have an idea on how to fix it or do you need further information on my code?
How to add salt ?
Your use of QByteArray::insert(int, int, char) was added in 5.7, meaning builds with 5.6 break.
Perhaps you could add some ifdefs around the code and another method for performing the same operation?
const quint8 sbox[256] = {
Any ideas to fix this?
ASSERT: "uint(i) < uint(size())" in file C:/Qt/5.12.0/mingw73_64/include/QtCore/qbytearray.h, line 481
it do this when it goes to the line 416 qaesencryption.cpp
QByteArray expandedKey = expandKey(key);
windows 7 qt 5.12
Hi
Is there a method to derive iv from password ? without salt, basically I need to replicate this openssl command on iOS and Android:
openssl enc -aes-128-ecb -a -K MY_KEY -k 'MY_PASS' -in mesg.enc
Best,
Marek
Реализована ли у вас возможность использовать библиотеку, так чтобы она автоматически выбирала подходящий метод в зависимости от возможностей процессора?
Do you have the ability to use a library so that it automatically selects the appropriate method depending on the processor's capabilities?
I have an issue, I'm developing an android app that comunicate with a Qt develop application through an UDP socket.
Just to study, I tried to encrypt comunication using AES CFB NoPadding:
Java side:
public final String key = "123456789123";
public final byte initVector[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
byte [] hashKey = null;
Cipher m_encChiper;
Cipher m_decChiper;
//Init
MessageDigest digest = MessageDigest.getInstance("SHA-256");
hashKey = digest.digest(msgTools.key.getBytes("UTF-8"));
IvParameterSpec iv = new IvParameterSpec(msgTools.initVector);
SecretKeySpec skeySpec = new SecretKeySpec(hashKey, "AES");
m_encChiper = Cipher.getInstance("AES/CFB/NoPadding");
m_encChiper.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
m_decChiper = Cipher.getInstance("AES/CFB/NoPadding");
m_decChiper.init(Cipher.DECRYPT_MODE, skeySpec, iv);
//Enc and Dec function
public byte[] encrypt(String value) {
try {
byte[] encrypted = m_encChiper.doFinal(value.getBytes());
return encrypted;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public String decrypt(byte [] encrypted) {
try {
byte[] original = m_decChiper.doFinal(encrypted);
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
Qt Side:
QAESEncryption *encryption = NULL;
QString key = "123456789123";
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray iv;
encryption = new QAESEncryption(QAESEncryption::AES_256, QAESEncryption::CFB);
quint8 iv_16[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
for (int i=0; i<16; i++)
iv.append(iv_16[i]);
QByteArray SenderThread::encryptData(QString msg)
{
return encryption->encode(msg.toLocal8Bit(), hashKey, iv);
}
QString SenderThread::decodeData(QByteArray xMsg)
{
return QString(encryption->decode(xMsg, hashKey, iv));
}
The problem is that, sending a string that encoded in java result in a 17 byte buffer, will be decoded in Qt correctly for the first 16 byte than QAESEncryption::decode at:
...
case CFB:
if (i+m_blocklen < rawText.size()){
ret.append(byteXor(rawText.mid(i+m_blocklen, m_blocklen),
cipher(expandedKey, rawText.mid(i, m_blocklen))));
...
with i = 0 m_blocklen = 16, append other 16 bytes, the first is the correct 17th others 15 are non sense...
The same sended string has been encoded locally in Qt resulting in a 32 byte buffer that are corretly decoded.
The same sended string has been encoded locally in Java resulting in a 17 byte buffer that are corretly decoded.
any idea on what's wrong when I pass from a platform to another??
Thanks a lot for all
When using this library for decryption, an out of memory error may occur when the length of the string to be decrypted does not match. It is currently believed that when using the mid() function on QByteArray, it may be necessary to determine if the length limit has been exceeded. Like this:
for (int i = 0; i < rawText.size(); i += m_blocklen)
{
if (i + m_blocklen > rawText.length())
{
break;
}
ret.append(invCipher(expandedKey, rawText.mid(i, m_blocklen)));
}
break;
I am not good at English, so I use translation tools. Please forgive me.Thank you!😄
I am using a machine with windows 10 installed and using Qt v15.5.2 with msvc x64 compiler.
Since last updates, it is used mingw macros I think for speeding up the thing, but now msvc is not supported.
Tested also with 1.0 version and the app is compiled under my system.
Hi,
While compiling it is giving undefined reference error at
/lan/ops/cdnshelp/cops/users/smunish/crypto/Qt-AES-master/Qt-AES-master/unit_test/aestest.cpp:197: undefined reference to `bool QTest::qCompare<QString, QByteArray>(QString const&, QByteArray const&, char const*, char const*, char const*, int)'
I use it(QT) to encrypt(AES128,ECB),key.length > 16
And I want to use nodejs to decrypt , It failed
Does it have anything to pay attention to, or does it not support
Of course, it may be my code problem, I hope to get some useful information
thx
Hi,
I am main developer of Ruqola (KDE Rocket chat client).
I want to implement encryption.
you can see how it works "https://docs.rocket.chat/customer-center/security-center/end-to-end-encryption-specifications"
Mainly we need to generate key:
"crypto.subtle.generateKey({name: 'RSA-OAEP', modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), hash: {name: 'SHA-256'}},
true, ['encrypt', 'decrypt']);"
and
RocketChat.E2E.crypto.generateKey({name: 'AES-CBC', length: 128}, true,
['encrypt', 'decrypt'])
Do you think that your lib can be use in my case ?
Thanks
Regards
When I try to encrypt data in the size of 1-2 GB it takes about 10 min to encrypt it with a 256 bit key in CBC mode with an 128 bit IV (Running Windows 10, i7-7700HQ, 24GB RAM).
Anything I could do to increase the speed?
Code snippet:
bigFileData.size() <== 1.9GB
key <== created with SHA256
iv <== created with Blake2s-128
QByteArray encodedText = aes.encode(bigFileData, key, iv);
Is there any plan to supporting AES GCM method?
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("[email protected]");
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
I'm currently at a point that requires me to decode an encrypted QByteArray but in my case it is possible for the passed data to be invalid.
If I now pass this invalid data through the decode()
method the entire app crashes, giving me the following error:
HEAP[MyApp.exe]: Heap block at 000001DA7A1C7B10 modified at 000001DA7A1C7B70 past requested size of 50
HEAP[MyApp.exe]: Invalid address specified to RtlValidateHeap( 000001DA706F0000, 000001DA7A1C7B20 )
Debug Assertion Failed!
Program: ...sktop_Qt_5_12_8_MSVC2017_64bit-Debug\debug\MyApp.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 904
Expression: _CrtIsValidHeapPointer(block)
Using a try {} catch {}
doesn't work, since the error seems to corrupt the heap in some way.
I know I should fix the source of the problem rather than trying to fix the symptoms but I don't see a bulletproof way to do this in my case.
decode()
method or run by the user themselves prior to decoding if needed.decode()
method just throw a catch-able Error when the passed data is invalid.QByteArray decrypted_file_buffer_1 = QAESEncryption::Decrypt(QAESEncryption::AES_256, QAESEncryption::CBC, encrypted_file_buffer_1, hash_key, hash_iv);
QByteArray decrypted_file_buffer_2 = QAESEncryption::Decrypt(QAESEncryption::AES_256, QAESEncryption::CBC, encrypted_file_buffer_2, hash_key, hash_iv);
Calling like this for multiple file buffers results in random heap corruption.
It doesn't happen while using openssl.
Hi,
Thank you for your job.
I would like to use QAESEncryption object to encrypt and decrypt some tokens generated by the Google API (https://github.com/ptstream/QtUPnP).
To test your code I try a simple program.
#include <QCoreApplication>
#include "qaesencryption.h"
#include <QCryptographicHash>
#include <QDebug>`
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QAESEncryption encryption (QAESEncryption::AES_256, QAESEncryption::CBC);
QByteArray input("uuid:e18d497c-e09b-4154-af73-ed7e69d142e8:uuid:2a684c04-66f5-448b-b905-f162334ea75d");
QByteArray key("your-string-key");
QByteArray iv ("your-IV-vector");
QByteArray hashKey = QCryptographicHash::hash(key, QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv, QCryptographicHash::Sha256);
QByteArray encodeText = encryption.encode(input, hashKey, hashIV);
qDebug () << encodeText;
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);
qDebug () << decodeText;
qDebug () << input;
return 0;
}
The function encode return always an empty QByteArray.
This is due to the first test where m_blocklen=16, Out the QCryptographicHash::hash returns a QByteArray with a length of 32.
If I rewrite the constructor like this:
// Change m_blocklen(16) by m_blocklen(32)
QAESEncryption::QAESEncryption(QAESEncryption::AES level, QAESEncryption::MODE mode)
: m_nb(4), m_blocklen(32), m_level(level), m_mode(mode)
it seems to work
I do not know anything about cryptography.
Best regards
Patrice
Lovely library and been working without issues for osx. However, trying to use with windows and having issues. Debug works fine and the same output is generated (as on osx)
However Release comes out with something wrong. I don't have a windows box in front of me so did a remote debugging session over skype which is a fairly slow process and found that the issue begins after calling expandKey
https://github.com/bricke/Qt-AES/blob/master/qaesencryption.cpp#L397
The expanded key is different.
Please note there are also some warnings, for type mismatch in windows for example:
ret.lastIndexOf(0x80)
This could maybe be a clue to some of the issues.
Hi all, I'm a newbie.
I tried to use Padding::ZERO with CBC mode.
However, the output is not fine.
I tested this output on some online tool and the result is not matching
Is it an issue?
If the size of encoded data is wrong, the decode() will cause heap corruption. So suggest that decode() should verify the length of input rrawText. It the lenght is not mutiple of 16 bytes(AES block), return an empty buffer.
Example code:
QByteArray encodedText("123456"); // wrong length
// QByteArray encodedText("1234561234561234"); does not cause failure.
QByteArray hashKey = QCryptographicHash::hash(seed, QCryptographicHash::Sha256);
QByteArray decoded = QAESEncryption::Decrypt(QAESEncryption::AES_128, QAESEncryption::ECB, encodedText, hashKey);
QByteArry res = QAESEncryption::RemovePadding(decoded);
This will cause
HEAP CORRUPTION DETECTED: after Normal block (#42796) at 0x0000023DF89F0770.
CRT detected that the application wrote to memory after end of heap buffer.
error C2536: “QAESEncryption::QAESEncryption::sbox”: 无法指定数组的显式初始值设定项
c:\qt\gitcode\qt-aes\debug../qaesencryption.h(83) : 参见“QAESEncryption::sbox”的声明
It's meaning cann't init this sbox array
Hi, after the string is encrypted, it is decrypted. The decrypted string is filled with other characters, such as:
Before encryption:NAAAACA9ARUMGMCJ2EPLCHKTF
After decryption:NAAAACA9ARUMGMCJ2EPLCHKTF\x80\x00\x00\x00\x00\x00\x00
I checked the source code, should I call removePadding function before QAESEncryption::decode returns to solve the problem?
It will crash in MinGW32
ASSERT: "uint(i) < uint(size())" in file c:\work\build\qt5_workdir\w\s\qtbase\src\corelib\tools\qbytearray.h, line 464
I'm not an encryption expert so I may miss something. While evaluating the library I noticed that ISO padding leaves 3 leading zeroed bytes in the plaintext. PKCS7 works fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.