It has been a long time since I programmed in C and this is my first
attempt at C++. I have a program that does Encryption a Decryption but I
need to use the Des-EDE2/3 algorithm. I've spent the better part of a week
trying to figure how to do this but I just realized that what I doing is
wrong.

How do I convert the following to use the Des-ede2/3 algorithm

//-----------------------------------------------------------------------------------------------

#include "default.h"
#include "des.h"
#include "hex.h"

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

#include <windows.h>

USING_NAMESPACE(CryptoPP)
USING_NAMESPACE(std)

int main()
{

const int MAX_PHRASE_LENGTH=250;

    byte * ciphertext;
    byte * result;

      HexEncoder hexEncoder3;

      const byte key[] = {
                  0x1c, 0xd5, 0x7f, 0x1f, 0xa7, 0x46, 0x1f, 0xe6,
                  0xc1, 0x26, 0x15, 0x54, 0x79, 0xfe, 0xcb, 0xe3,
                  0x89, 0x01, 0x1f, 0x16, 0x9e, 0x04, 0xd3, 0x61};

      const byte iv[]  = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};

      const byte plaintext[] = {    // "Now is the time for all " without
tailing 0
            0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
            0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
            0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};

      DESEncryption desE(key);
      DESDecryption desD(key);


      cout << "\nTesting DES modes...\n\n";

    // encrypt
    CBC_Mode_ExternalCipher::Encryption cbcE(desE, iv);
    StreamTransformationFilter encryptor(cbcE, NULL,
StreamTransformationFilter::NO_PADDING);
    encryptor.Put(plaintext, sizeof(plaintext));
    encryptor.MessageEnd();

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

      hexEncoder3.Put(ciphertext,outputLength);
      hexEncoder3.MessageEnd();
      byte pData3[outputLength*2];
      hexEncoder3.Get(pData3,outputLength*2);

      cout << "\nEncrypted Data is: " << pData3 << endl;

    // now decrypt
    CBC_Mode_ExternalCipher::Decryption cbcD(desD, iv);
    StreamTransformationFilter decryptor(cbcD, NULL,
StreamTransformationFilter::NO_PADDING);
    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