C++ Des encryption with 16 bytes key
<p>I'm trying to encrypt in DES a text with dynamic length with a 16 bytes key, but there is a problem with the block size of the key and text, i'm using openssl library for DES encryption. How can I use keys with 16 bytes of length.</p>

<p>Here my example:</p>

<pre><code>char * Encrypt( char Key, char *Msg, int size) { 
      static char*    Res;
      DES_cblock      Key2;
      DES_key_schedule schedule;

      Res = ( char * ) malloc( size );

      memcpy(Key2, Key, 8);
      DES_set_odd_parity( &amp;Key2 );
      DES_set_key_checked( &amp;Key2, &amp;schedule );

      unsigned char buf[9];    
      buf[8] = 0;

      DES_ecb_encrypt(( DES_cblock  ) &amp;Msg, ( DES_cblock  ) &amp;buf, &amp;schedule, DES_ENCRYPT );    
      memcpy(Res, buf, sizeof(buf));    
      return (Res);
}

int main(int argc, char const *argv[]) {
      char key[] = "password";
      char clear[] = "This is a secret message";
      char *encrypted;

      encrypted = (char *) malloc(sizeof(clear));

      printf("Clear text\t : %s \n",clear); 

      memcpy(encrypted, Encrypt(key, clear, sizeof(clear)), sizeof(clear));

      printf("Encrypted text\t : %s \n",encrypted);
      return 0;
}
</code></pre>