If you have a good example of simply encrypting a file using openssl that is better than this one that I am having issues with I would be very grateful.
Up
Since you say the error seems to be coming at the decryption stage, I would look with suspicion on these lines:
if (EVP_DecryptUpdate (&ctx, outbuf, &olen, inbuff, n) != 1)
...
if (EVP_DecryptFinal (&ctx, outbuf + olen, &tlen) != 1)
...
How big is the memory allocated for outbuf in relation to what the decryption functions will be putting in them? Are you sure outbuf + olen is not going to take you past the end of the buffer?