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.