Hi,

>why the reverse of
>
>   CBC_Mode<AES>::Encryption encrAES;
>   ......................
>   Base64Encoder *baseEnc = new
>     Base64Encoder(new FileSink("tenc.txt"));
>   StreamTransformationFilter aesEnc(encrAES, baseEnc);
>
> does not seem to work? I mean - in the above I can do
>
>   aesEnc.Put(plaintext, len);
>   aesEnc.MessageEnd();
>
> and the encrypted+encoded record gets stored in the file (program runs and
> the resulting file looks good).
>
> I need the reverse now, that I could use like
>
>   len = aesDec.Get(decrypted, maxLen);
>

Without seeing the code that doesn't work (i.e. precisely what you're
doing to "reverse" the process), it's hard to say why it doesn't work
for you. If you simply don't give the StreamTransformationFilter an
attachment, though, it behaves exactly as you wish.

Here's a block (certainly still trivial, but less so :) ) that illustrates:

{
        string plaintext( "I think Smithers picked me because of my
motivational skills."
                                          "Everyone says they have to work a 
lot harder when I'm around.\n");
        string encfile("encrypted.txt");

        SecByteBlock key,iv;
        
        key.New(AES::DEFAULT_KEYLENGTH);
        iv.New(AES::BLOCKSIZE);
        
        AutoSeededRandomPool rng;
        rng.GenerateBlock(key,AES::DEFAULT_KEYLENGTH);
        rng.GenerateBlock(iv,AES::BLOCKSIZE);
        
        cout << "Plaintext: " << plaintext << endl;
        CBC_Mode<AES>::Encryption encryptor(key,AES::DEFAULT_KEYLENGTH,iv);
        StringSource incoming(plaintext, true,
                new StreamTransformationFilter( encryptor, new Base64Encoder(new
FileSink(encfile.c_str()))));
        cout << "Encrypted data written to: " << encfile << endl;
        
        // initialize the block cipher with the same key and IV used for 
encryption
        CBC_Mode<AES>::Decryption decryptor(key,AES::DEFAULT_KEYLENGTH,iv);
        // Create a stream transformation filter for the block cipher that
has no attachment
        StreamTransformationFilter * outfilt = new
StreamTransformationFilter(decryptor);
        // create a file source that pumps the data from the file above
through a base64 decoder to
        // the filter for decryption
        FileSource outgoing(encfile.c_str(), true, new Base64Decoder(outfilt));
        
        // get recovered data whatever size increments you care to
        unsigned long messagelen = 1;
        SecByteBlock recoveredbytes;
        while(outfilt->AnyRetrievable())
        {
                recoveredbytes.CleanNew(messagelen+1);
                unsigned long retrieved = 
outfilt->Get(recoveredbytes,messagelen);
                cout << "Recovered " << retrieved << " bytes: " <<
(char*)(recoveredbytes.data()) << endl;
                messagelen += 2;
        }       
}

The loop at the end is a silly example, but I think it shows how to do
what you want. As before, feel free to use, post to the wiki/faq, or
disregard as you wish.

HTH,

Geoff

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