Hi,

Sorry if this is a stupid question, but I know almost nothing about 
cryptography theory but I need
to encrypt and decrypt a message using DES ....

But for now I can't figure out what should be the Initialization Vector ... the 
guys who encrypted
the msg have no idea wich iv was used (they have no idea what is iv since they 
are using a product
built in encryption api call) ... I have read somewhere that with DES the IV 
should be the key
vector, but I'm not getting their result when encrypting the same message with 
the same key.

The code bothered from the FAQ ... note that plaintext and key are already 
created as a byte array
.... could someone point me to some direction? (the expected result is 0x21 
0x79 0xAD 0xB9 0x24 0x59
0xEE 0xE3)

      //lenght Needs to be a multiple of 8
      byte plaintext[] = { 0x06, 0x12, 0x34, 0x56, 0xFF, 0xFF, 0xFF, 0xFF };
      byte * ciphertext;
      byte * result;

      HexEncoder hexEncoder3;
      unsigned int outputLength;

      const byte key[] = { 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61 };

      // encrypt
      CBC_Mode<DES>::Encryption ecbEncryption(key,DES::DEFAULT_KEYLENGTH, key);
      StreamTransformationFilter encryptor(ecbEncryption,
NULL,StreamTransformationFilter::NO_PADDING);
      encryptor.Put(plaintext, sizeof(plaintext));
      encryptor.MessageEnd();

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

      cout << "outputLength is: " << outputLength << endl;

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

      int j=0;
      cout << "Encrypted Data is: ";
      for (j=0; j<(outputLength*2); j++) {
             cout << pData3[j];
      }
      cout << endl;

      // now decrypt
      CBC_Mode<DES>::Decryption ecbDecryption(key,
                                          DES::DEFAULT_KEYLENGTH, key);
      StreamTransformationFilter decryptor(ecbDecryption, NULL,
                                          
StreamTransformationFilter::NO_PADDING);
      decryptor.Put(ciphertext, outputLength);
      decryptor.MessageEnd();

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

      cout << "ciphertext size is " << sizeof(ciphertext) << endl;
      cout << "recovered plaintext is " << result << endl;


      delete [] ciphertext;
      delete [] result;

      return 0;

Reply via email to