Im not sure that I explained this correctly.
I have a php script (encrypt.php) that runs from my site and encrypts the file just fine with gpg encryption.
Im using the code below to encrypt the file, except the secret file can be any format (.doc, .ppt, .xls, etc...), but this is basically the code I used for encryption (And it works).
here is the page where I got the code from
Code ref page
$gpg = '/usr/bin/gpg';
$recipient = 'email@example.com';
$secret_file = 'secret_file.txt';
echo shell_exec("$gpg -e -r $recipient $secret_file");
now when decrypting the file using basically the same command to encrypt it, it does not work.
$gpg = '/usr/bin/gpg';
$passphrase = 'My secret pass phrase.';
$encrypted_file = 'foo.gpg';
$unencrypted_file = 'foo.txt';
echo shell_exec("echo $passphrase | $gpg --passphrase-fd 0 -o $unencrypted_file -d $encrypted_file");
i can run both of these commands from the terminal shell and they both work just fine, but when running from the php script (encrypt.php and decrypt.php) the encrypt works and the decrypt does not.
also when running encrypt.php and decrypt.php the user that apache allows to execute these pages is the 'nobody' user which has very limited privileges. I think this is the cause for the decrypt.php script not to work.
Also I forgot to mention the encrypt.php script is owned by 'my_user' and generates the decrypt.php file based on the file and directory. But the generated decrypt.php file is owned by the 'nobody' user.
I have even taken out the decrypt function and placed it in its own file (wth 'my_user' as the owner) and then did an include in the generated php script, but still no go.
I have posted another thread about this as well but no one responded.
Link to other post
The question I had is if I can use something to change the user 'nobody' to 'my_user' while running my php script from the web with NO terminal access, just echo'ing a command or using a process like sessions to change the user.
I tried your suggestion in earlier testing with my script and revisited it when you posted (Thanks for the advice) but it's still not working.
The idea behind the script and its functionality is to upload a file of a specific size or less, encrypt it on my server. when some_user goes to retrieve the file, decrypt it and then download.
seems simple enough, and I have done everything else except the decryption. maybe its the code?
any other suggestions or thought will be welcomed.