Search code examples
phpencryptiongnupgsecret-keypassphrase

How to decrypt an encrypted file by passing the "gpg passphrase" in the command using PHP?


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.


Solution

  • You should probably use the php functions instead of forking gpg