Do you mean like:
#include "default.h"
#include "des.h"

#include <iostream>
#include <time.h>

#include <windows.h>

#if (_MSC_VER >= 1000)
#include <crtdbg.h>             // for the debug heap
#endif

USING_NAMESPACE(CryptoPP)
USING_NAMESPACE(std)


int main()
{
// Note the for ECB, the PlainText and Cipher Text MUST be an EXACT multiple
// of the cipher blocksize
        byte plaintext[48] = {'H','e','l','l','o','
','W','o','r','l','d','\0'};
        byte * ciphertext;
        byte * result;
        byte key[DES::DEFAULT_KEYLENGTH];

        // initialize key and iv here
        memcpy(key, "12345678", sizeof(key));


        // encrypt
        ECB_Mode<DES>::Encryption ecbEncryption;
        ecbEncryption.SetKey(key, ecbEncryption.DefaultKeyLength());
        StreamTransformationFilter encryptor(ecbEncryption, NULL, NULL);
        encryptor.Put(plaintext, sizeof(plaintext));
        encryptor.MessageEnd();

        unsigned int outputLength = encryptor.MaxRetrievable();
        ciphertext = new byte[outputLength];
        encryptor.Get(ciphertext, outputLength);

        // now decrypt
        ECB_Mode<DES>::Decryption ecbDecryption;
        ecbDecryption.SetKey(key, ecbDecryption.DefaultKeyLength());
        StreamTransformationFilter decryptor(ecbDecryption, NULL, NULL);
        decryptor.Put(ciphertext, outputLength);
        decryptor.MessageEnd();

        outputLength = decryptor.MaxRetrievable();
        result = new byte[outputLength];
        decryptor.Get(result, outputLength);

        cout << "recovered plaintext is " << result << endl;

        delete [] ciphertext;
        delete [] result;
        return 0;
}


Reply via email to