Search code examples
cryptographyencryptioncrypto++

Crypto++ AES Decrypt how to?


There are next to no noob guides to crypto++ out there. Or none that I've found anyway. What I want to do is decrypt an array of uchars I generate with another AES encrypter. Where would I start? I have the library built and linking grand. Do I need to set anything up or do I just call a function on my array (and if so what function) ?

I'd really appreshiate some help from someone who knows this stuff.

Thanks


Solution

  • I wouldn't say I "know my stuff" too much about this, but here's some test code I put together to encrypt/decrypt strings with AES. Extending this to use some other data shouldn't be too hard.

    string output;
    CTR_Mode<AES>::Encryption encrypt((const byte*)key,AES::DEFAULT_KEYLENGTH,(const byte*)iv);
    StringSource(plaintext, true, new StreamTransformationFilter(encrypt, new StringSink(output)));
    cout << "Encrypted: " << output << endl;
    
    string res;
    CTR_Mode<AES>::Decryption decrypt((const byte*)key,AES::DEFAULT_KEYLENGTH,(const byte*)iv);
    StringSource(output, true, new StreamTransformationFilter(decrypt, new StringSink(res)));
    cout << "Decrypted: " << res << endl;
    

    While working on this, I found the source code in the Crypto++ test program (the VisualStudio project called "cryptest") to be a big help. It was a little tough to read at first, but it gets easier as you work with it. I also got a lot of help understanding the available block cipher modes from Wikipedia (http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation).