1
votes

I would like to know how can i decrypt a file by passing the passphrase/secret key in the command line.

I tried using this, but its still giving me a prompt to enter the passphrase.

echo shell_exec("echo $passphrase | gpg --passphrase-fd 0 -o $unencrypted_file -d $encrypted_file");

My goal is to created a program in PHP that can decrypt the files automatically.

3

3 Answers

2
votes

You should probably use the php functions instead of forking gpg

0
votes

I don't know what approach the gpg developers were using to prevent that. But as an alternative you can use this PHP module: http://pecl.php.net/package/gnupg to handle the decryption. See also http://php.net/gnupg

0
votes
gpg --passphrase-file $file

man gpg says : "Read the passphrase from file file. Only the first line will be read from file file. This can only be used if only one passphrase is supplied. Obviously, a passphrase stored in a file is of questionable security if other users can read this file. Don't use this option if you can avoid it."