[Botan-devel] Botan: Decoding error: AES/CBC/PKCS7
lloyd at randombit.net
Thu Apr 14 09:43:05 EDT 2005
On Thu, Apr 14, 2005 at 02:35:34AM -0400, Jawwad Shamsi wrote:
> I have two questions
> I am trying to write a program which has two parts
> 1) Part 1 reads plain text from file, encrypts it and writes the cipher to
> the output file
> 2) Part 2 reads the cipher text from file , decrypts it and writes the
> plain text to another output file .
> The program uses symmeric key, However I am unable to get the 2nd part
> working and getting Decoding error: AES/CBC/PKCS7
That is because your first Pipe is
Pipe pipe(get_cipher("AES/CBC/PKCS7", key,iv, ENCRYPTION),
and your second is
Pipe pipe2(get_cipher("AES/CBC/PKCS7", key, iv, DECRYPTION));
which doesn't match up; the ciphertext is base64 encoded but you never do the
cooresponding base64 decode prior to decrypting it. So you'd want to either add
a Base64_Decoder before the cipher in pipe2, or remove the Base64_Encoder in
> Also, I was wondering if it is possible to encrypt a C++ object like
> structure ?
It is, but you would have to serialize them to a bytestream somehow. There are
different levels of complexity in such a setup, for example simply serializing
to a fixed format, or doing type tagging, or even serializing the code attached
to the object (which is a pretty crazy thing to do in C/C++, a little more
reasoanble in some other languages).
You can do it by hand, or there are frameworks for it (Googling for "C++ object
serialization" shows some results that may be helpful). If you're going to be
serializing a lot of different objects and there are no standard layouts for
any of them, you might want to consider learning a bit of ASN.1 and then using
Botan's DER encoder support. However, that's a lot of work if you're only
planning on doing a small number of objects (or if you're in a hurry).
I just found that Boost has a serialization framework of some sort as
well. That may be one to consider.
More information about the botan-devel