DES-EDE3 needs 24 bytes of key. If you want 2-key Triple-DES, use DES-EDE2.

On Mon, Sep 30, 2002 at 10:16:36AM +0200, Inmaculada Martinez wrote:
> 
> Hi again!
> I have continued working with my program since the last time I wrote to you.
> Unfortunately, I have another problem with the encription. I am using
> Triple-DES algorithm to encode a plain text, but when I try decode it, I do
> not get the original text, I get something encrypted.
> 
> This is my source code, is it all right??
> 
>       CString Texto,Texto2,Texto3;
>       AutoSeededRandomPool rng;
>       char *cadena= new char[10000];
>       int i,j;
>       // To obtain the plain text
>       GetDlgItem(IDC_TxtOriginal)->GetWindowText(Texto);
>       StringToChar(Texto, cadena);
>       byte key[16];   
>       rng.GenerateBlock(key, sizeof key);
> 
>       byte iv[DES_EDE3_Encryption::BLOCKSIZE];
>       rng.GenerateBlock(iv, sizeof iv);       
> 
>       // Encode text
>       DES_EDE3_Encryption en(key);
>       CBC_CTS_Encryptor encryptor(en, iv);
> 
>       encryptor.Put((byte *)cadena,sizeof (cadena));
>       encryptor.Close();
>       i = encryptor.MaxRetrieveable();
>       unsigned char *ciphertext = new byte[i];
>       encryptor.Get(ciphertext, i);
>       Texto2 = ciphertext;
>       // To put the encode text in a combobox
>       GetDlgItem(IDC_txtcifrado)->SetWindowText(Texto2);
> 
>       // Decode text
>       DES_EDE3_Decryption des(key);
>       CBC_CTS_Decryptor decryptor(des, iv);
>       
>       decryptor.Put((byte *)ciphertext,sizeof (ciphertext));
>       decryptor.Close();
> 
>       j = decryptor.MaxRetrieveable();
>       unsigned char *salida = new byte[j];
>       decryptor.Get(salida, j);
>       Texto3 = salida;
>       // To put decode text in the combobox
>       GetDlgItem(IDC_txtcifrado)->SetWindowText(Texto3);
> 
> 
> Please, if you do not mind checking it, i would be very grateful.
> 
> Thank you very much in advance.
> 
> Inma.

Reply via email to