title: Problem by Encryption & Decryption of text with EVP_des_ofb(), openSSL , C
body: <p>I need to encrypt and decrypt txt-file with DES-ofb (libcrypto) using OpenSSL library, the key and Init Vector is given in one bin.file(key+iv). But after the decryption via EVP_DecryptUpdate(), decrypted text and plain text are not similar at all. </p>
  
  <p><a href="https://i.stack.imgur.com/nkq9A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nkq9A.png" alt="Decryption Difficulties"></a></p>
  
  <p>So I read plain.txt 8 bytes and a 'keyandIV.bin' files. Than I took first 8 bytes from keyandIVbuffer as a KEY for DES and the rest as IV. So I have 8 bytes key and 8 bytes IV, added '\0'  at the end of both (Do I need '\0' here ? Key length must be 64 or 56 bits?).</p>
  
  <p>This is my code for ercryption with DES ofb:</p>
  
  <pre><code>printf("ENCRYPTION:\n");
  int howmany = 0, final1;
  const EVP_CIPHER *CIPHER_TYPE = EVP_des_ofb();
  EVP_CIPHER_CTX *ctx_encrypt = EVP_CIPHER_CTX_new();
  EVP_CIPHER_CTX_init(ctx_encrypt);
  
  EVP_EncryptInit(ctx_encrypt, CIPHER_TYPE, keybuf1, ivbuf1);
  if(!EVP_EncryptUpdate(ctx_encrypt, ciphertextbuf1, &amp;howmany, plaintextbuf1, plainlength1))return -1;
  if(!EVP_EncryptUpdate(ctx_encrypt, ciphertextbuf1, &amp;howmany, plaintextbuf1, plainlength1)) return -1;
  EVP_EncryptFinal_ex(ctx_encrypt, ciphertextbuf1 + howmany , &amp;final1);
  EVP_CIPHER_CTX_cleanup(ctx_encrypt);
  </code></pre>
  
  <p>Than I took the encrypted buffer und decrypt it so:</p>
  
  <pre><code>printf("DECRYPTION:\n");
  int final2;
  EVP_CIPHER_CTX *ctx_decrypt = EVP_CIPHER_CTX_new();
  EVP_CIPHER_CTX_init(ctx_decrypt);
  EVP_DecryptInit(ctx_decrypt, CIPHER_TYPE, keybuf1, ivbuf1);
  if(!EVP_DecryptUpdate(ctx_decrypt, decryptedtext, &amp;howmany, ciphertextbuf1, strlen(ciphertextbuf1))) return -1;
  if(!EVP_EncryptFinal_ex(ctx_decrypt, decryptedtext + howmany, &amp;final2)) return -1;
  EVP_CIPHER_CTX_cleanup(ctx_decrypt);
  </code></pre>
  
  <p>I definetly have understanding problem with DES. Maybe I did something wrong by creatimg key and IV from one file.I have seen plenty of examples but I still don't understand what I did wrong in my  program.</p>