Hi Stef,

> stfEncryptor.Put(reinterpret_cast<const unsigned
>    char*>(plaintext.c_str()), plaintext.length() + 1);
Do the scripts include the trailing '\0' of 'Hello'?

Jeff

On 2/5/08, StefSchultz <[EMAIL PROTECTED]> wrote:
>
> Testing the CFB Mode I've noticed that it gives me some strange
> results. I tested the same mode with the same IV and Key in a PHP and
> Python script:
>
> //----------------------------------
> //init key & iv
> $key = "xxxxxxxxxxxxxxxxxxxxxxxx";
> $iv = "xxxxxxxxxxxxxxxx";
>
> //print key
> echo ('key:           ' . $key . "\n");
> echo ('iv:            ' . $iv . "\n");
>
> //print iv
> echo ('----------------------------------------' . "\n");
>
> //original
> $original = 'hello';
> echo ('original:      ' . $original . "\n");
>
> //encode
> $encoded = mcrypt_cfb(MCRYPT_RIJNDAEL_128, $key, $original,
> MCRYPT_ENCRYPT, $iv);
> echo ('encoded (hex): ' . str2hex($encoded) . "\n");
>
> //decode
> $decoded = mcrypt_cfb(MCRYPT_RIJNDAEL_128, $key, $encoded,
> MCRYPT_DECRYPT, $iv);
> echo ('decoded:       ' . $decoded . "\n");
> //----------------------------------
>
>
> Both scripts returned the same ciphertext. However, after testing
> Crypto++ I got a different result. Only the first hex number was
> right. This ist the code:
>
>
> //----------------------------------
>        const unsigned int keyLength = 24;
>        byte key[24], iv[keyLength];
>        memset(key, 0x78, keyLength);
>        memset(iv, 0x78, AES::BLOCKSIZE);
>
>        string plaintext = "hello";
>        string ciphertext;
>        string decryptedtext;
>
>        cout << "Plain Text (" << plaintext.size() << " bytes)" <<
> endl
>             << plaintext << endl << endl;
>
>        AES::Encryption aesEncryption(key, 24);
>        CFB_Mode_ExternalCipher::Encryption
> cfbEncryption(aesEncryption, iv);
>        StreamTransformationFilter stfEncryptor(cfbEncryption, new
> StringSink(ciphertext),
>
> StreamTransformationFilter::NO_PADDING);
>
>        stfEncryptor.Put(reinterpret_cast<const unsigned
> char*>(plaintext.c_str()), plaintext.length() + 1);
>        stfEncryptor.MessageEnd();
>
>        cout << "Cipher Text (" << ciphertext.size() << " bytes)\n";
>
>        for(size_t i = 0; i < ciphertext.size(); i++)
>            cout << "0x" << hex << (0xFF &
> static_cast<byte>(ciphertext[i])) << " ";
> //----------------------------------
>
> Probably I did something wrong. Can somebody offer any help? :-)

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to