In 5.x, you'll want the factory to return a SymmetricCipher *, which is the interface supported by both block ciphers (when used with a Mode class) and stream ciphers. Then you can use StreamTransformationFilter to use it with the BufferedTransformation interface. StreamTransformationFilter also takes the object by reference. If you want the StreamTransformationFilter object to delete the SymmetricCipher object for you, you have to derive your own class from StreamTransformationFilter and delete it in the destructor of the derived class.

----- Original Message ----- From: "Giuliano Bertoletti" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, December 06, 2006 5:51 PM
Subject: Symmetric Cipher thorugh a Factory



Hello,

I'm trying to figure out how to write a Factory function that uses Crypto++ 5.0. It should build and return a properly initialized symmetric cipher encryptor (or decryptor).

In particular I wish to obtain an object which has the interface of a buffered transformation where I can put data and get processed data back.

In the old crypto 4.2 library I used to write code like this:

BlockTransformation *MyFactory( ... )
...
switch( cipher_id): {
          case CAST128_IN_CBC:
BlockTransformation *blockCipher = new CAST128Decryption(mySessionKey);
BufferedTransformation *obj = new CBCPaddedDecryptor(*blockCipher,iv);
return obj
...

/* ----------------- */
// and the caller...

obj = MyFactory( ... )

obj->Put(myEncryptedSecret,myEncryptedSecretSize);
obj->MessageEnd();
...
obj->Get( ... )

Aside from the fact that this code doesn't work in the Crypto 5.0 I'm using now, I've also another minor problem: I would like the container object to destroy the embeeded cipher passed (but he doesn't because the constructor takes it by reference).

My goal is to pass the cipher_id and the key to the factory and have it return the cipher, properly initialized (for example it should supply the IV if the cipher mode needs one).

The object should be transparent outside, meaning that it should behave correctly despite the fact it's working either as a block cipher or as a stream cipher. He should simply be able to receive data, process it and return the result.

Could you suggest which base class to use and a few sample line on how to instantiate a cipher encryptor (say, an AES CBC block cipher). ?

Regards,
Giuliano Bertoletti.







Reply via email to