tags:

views:

60

answers:

1

Based on QCA::Cipher Example I managed to get an encrypted value.

String:  hellohellohellohello
Encoded: d2fde01cb467a97de2e56bbd76fb0855
Key:     cekpo
IV:      cekpo

My code:

QString enc = "d2fde01cb467a97de2e56bbd76fb0855";

QCA::Initializer init;

QCA::SymmetricKey key(QByteArray("cekpo"));
QCA::InitializationVector iv(QByteArray("cekpo"));

QCA::Cipher cipher(QString("aes128"),
                   QCA::Cipher::CBC,
                   // use Default padding, which is equivalent to PKCS7 for CBC
                   QCA::Cipher::DefaultPadding,
                   // this object will encrypt
                   QCA::Decode,
                   key, iv);


QCA::SecureArray cipherText = QByteArray("d2fde01cb467a97de2e56bbd76fb0855");

printf("Decoded: %s\n", QCA::SecureArray(cipher.process(cipherText)).data() );

My question is, how can I decode it back to the original string ?

A: 

You need to use QCA::hexToArray on enc before passing to cipher.process(), i.e.

QCA::SecureArray cipherText = QCA::hexToArray(QString("d2fde01cb467a97de2e56bbd76fb0855"));
GregS
It's not working, I got (null), is there anything else I need to change ?
aurorius
By the way, my new codes based on your suggestion: http://www.pastebin.ca/1896551
aurorius
Thanks for posting the code. I'll try and find some time tonight to investigate this further.
GregS