PDA

View Full Version : Crypto++ and QByteArray



Urvin
28th September 2010, 15:12
Please, help me to crypt a Qt byte array using Crypto++ library and TEA algorythm!

Looking at QCrypto from qt-apps I see, that to crypt standart string with a byte key I should use this:

string lInputText;
string lResultText;
QByteArray fEncryptionKey;

...

byte lKey[TEA::DEFAULT_KEYLENGTH];
byte lIVector[TEA::BLOCKSIZE];

StringSource(reinterpret_cast<const char*>(fEncryptionKey.data()), true,
new HashFilter(*(new SHA256), new ArraySink(lKey, TEA::DEFAULT_KEYLENGTH))
);
memset(lIVector, 0x00, TEA::BLOCKSIZE);

CBC_Mode<TEA>::Encryption Encryptor(lKey, sizeof(lKey), lIVector);

StringSource(lInputText, true,
new StreamTransformationFilter(Encryptor,
new HexEncoder(new StringSink(lResultText)))
);


But what should I do if I have QByteArray InputData, QByteArray Key and I want to have QByteArray OutputData at output?
Thanks!