> Some modes of operations of block ciphers (CBC and ECB) 
> require that the plaintext be processed in blocks. 
> MessageEnd() tells the StreamTransformationFilter to pad the 
> final block and output the last block of ciphertext.

That means, that a program that creates output into
StreamTransformationFilter  containing CBC encryptor (and tries to force
each individual record out), using something like:

  for (i=0; i < total; i++) {
    encrStream.Put(record[i], record[i].size());
    encStream.MessageEnd();
  }

is perfectly correct?

How then to read such a file? My program that tried to create
StreamTransformationFilter intaking from FileSource(that_encrypted_file),
crashed consistently on the code line that tried to attach FileSource to the
decrypting filter.

Could you please give a code example of how to correctly read an encrypted
file created with MessageEnd() invocation after each logical record?
Perhaps some parameters in the following lines that I'm missing? Please
clarify them.

  SecByteBlock recbytes;
  CBC_Mode<AES>::Decryption decrAES(aesDKey, 32, aesDIV);
  StreamTransformationFilter *aesD =
    new StreamTransformationFilter(decrAES);
  FileSource fstxt("tenc.txt", true, new Base64Decoder(aesD));

Thank you!


> On the 
> decryption side, you have to call MessageEnd() at the right 
> place (i.e., after inputting all of the ciphertext) to tell 
> StreamTransformationFilter to unpad the final block.

But how? The code (see below) crashes consistently even before I get a
chance to invoke anything on the FileSource object. Also, I thought that if
the file contains multiple records with MessageEnd() after each one - then
NumberOfMessages() invokec by the reader should give the number of records
in that file. Why doesn't it work? Or (if I misunderstand the purpose of
that method) how/when does it work?

  CBC_Mode<AES>::Decryption decrAES(aesDKey, 32, aesDIV);

  SecByteBlock recbytes;

  StreamTransformationFilter *aesD =
    new StreamTransformationFilter(decrAES);
  // This line is where code crashes if "tenc.txt" is
  // created using multiple MessageEnd() invocations
  FileSource fstxt("tenc.txt", true, new Base64Decoder(aesD));

  cout << "have " << aesD->MaxRetrievable() << " bytes ready\n";

  int i=0, len=0;
  while (aesD->AnyRetrievable()) {
    recbytes.CleanNew(100);
    // why aesD->NumberOfMessages() does not
    // return the number of invocations of
    // MessageEnd() by file creator?
    i = aesD->MaxRetrievable();
    // here I want to read up to the next MessageEnd().
    // how can I determine the actual length prior to
    // performing the Get()?
    len = aesD->Get(recbytes, i);
    // Should I call aesD->MessageEnd() here?
    cout << "Got " << len << " bytes: \"" 
         << (char *)recbytes.data() << "\"\n";
  }

> To answer your other question of building 5.5.2 under MS 
> Visual Studio 2003, open "cryptest.dsw" and convert it. 

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

Reply via email to