title: OpenSSL Decryption - EVP_DecryptFinal_ex fails
body: <p>I'm using this decryption function to get the plain text value of a cipher which was encrypted using EVP AES 265 GCM; I can see data in <code>rawOut</code> but <code>ret = EVP_DecryptFinal_ex(ctx, rawOut, &amp;len);</code> returns 0; can you provide any insight as to why? I've also seen sources which do <code>rawOut + len</code> in the <code>EVP_DecryptFinal_ex</code> code, I'm not sure why this would be needed as it would move the pointer to the end of the buffer.</p>
  
  <pre><code>unsigned char* keyDecrypter(unsigned char* pszMasterKey)
  {
      ERR_load_crypto_strings();
  
      int ret, len;
      EVP_CIPHER_CTX* ctx;
      unsigned char* rawOut = new unsigned char[48]; // ToDo Remove Hardcoded Value
  
      Info info = m_header.processKeyInfo();
      if (NULL == info.nonce)
          return NULL;
  
      if (!(ctx = EVP_CIPHER_CTX_new()))
          return NULL;
  
      if (!EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, pszMasterKey, info.nonce))
          return NULL;
  
      if (!EVP_DecryptUpdate(ctx, NULL, &amp;len, m_header.aad, m_header.aad_len))
          return NULL;
  
      if (!EVP_DecryptUpdate(ctx, rawOut, &amp;len, m_header.encryptedValue, m_header.encryptedValueLen))
          return NULL;
  
      // Finalise the decryption. A positive return value indicates success,
      // anything else is a failure - the plain text is not trustworthy.
      ret = EVP_DecryptFinal_ex(ctx, rawOut, &amp;len);
  
      ERR_print_errors_fp(stderr);
  
      EVP_CIPHER_CTX_free(ctx);
  
      if (ret &gt; 0)
      {
          return rawOut;
      }
      else
      {
          return NULL;
      }
  }
  </code></pre>