Hi,
change the user to the apache, and run your test script again. Probable the problem it's not there, but ...
And in the CGI, save the file before encryption and check if it's correct.
And the last, but not the least debug. If you hare using the
CGI you can do the debuging easily in the command line.
ps. this node it's interesting
Debugging a CGI.