Hi there,

trying to encrypt something with crypto++ and aes and i have a weired 
problem.

When i encrypt and then decrypt, the decrypted texts first 16 bytes are 
scrambled.

I am developing using Qt 4.8

Here is the code:

Making the password:

CryptoPP::SecByteBlock Encrypter::makeKey(int keySize)
{
    CryptoPP::AutoSeededRandomPool rng;

    CryptoPP::SecByteBlock secKey(0x00, CryptoPP::AES::MAX_KEYLENGTH);
    rng.GenerateBlock( secKey, secKey.size() );

    return secKey;
}

// encrypting a string to base64

QString Encrypter::encryptMessage(const QString &msg, const 
CryptoPP::SecByteBlock &key)
{
    CryptoPP::AutoSeededRandomPool rng;

    byte iv[CryptoPP::AES::BLOCKSIZE];
    rng.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE);

    char buf[msg.length()];

    CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption cfbEncryption(key, 
key.size(), iv);
    cfbEncryption.ProcessData((byte *)buf, (byte 
*)msg.toStdString().c_str(), msg.length());

    QByteArray ret(buf, msg.length());
    return ret.toBase64();
}

// decrypting string from base 64
QString Encrypter::decryptMessage(const QString &msg64, const 
CryptoPP::SecByteBlock &key)
{
    CryptoPP::AutoSeededRandomPool rng;

    byte iv[CryptoPP::AES::BLOCKSIZE];
    rng.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE);

    QByteArray msg = QByteArray::fromBase64(msg64.toUtf8());
    char buf[msg.length()];

    CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption cfbDecryption(key, 
key.size(), iv);
    cfbDecryption.ProcessData((byte*)buf, (byte*)msg.data(), msg.length());

    QByteArray ret(buf, msg.length());
    return QString(ret);
}

And here is the output:

 ================= Orig Message: 

"<?xml version="1.0"?><msg rcpt="aggi"><txt><![CDATA[Dies ist eine 
Test-Message]]></txt></msg>

" 

================= Encrypted Message: 

"Rx0p97beXpzc/kx7I0hlIm1IjDrkeR7hurTabRSisqGfRTwox3MFnM+n93naCLw75Na9Af+OG7IwI3KJYnX1QC8pmO7Bfl3Cq4B18xbHZbzuug0aPWhO4nGt3fiwbA=="
 


================= Decrypted Message: 

" :wˆ 5 G  ®¸¥ÿ  .0"?><msg rcpt="aggi"><txt><![CDATA[Dies ist eine 
Test-Message]]></txt></msg>

"


not all scrambled bytes were pasted in, it is always exactly 16 and not on 
every block, even if i make a large text for encryption, its always only 
the first 16

Any idea what this can be?

Thank you.

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to