Rider
Rider

Reputation: 1003

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.

Upvotes: 1

Views: 3816

Answers (3)

Bluewind
Bluewind

Reputation: 1064

You should probably use the php functions instead of forking gpg

Upvotes: 2

Olivier Delrieu
Olivier Delrieu

Reputation: 782

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."

Upvotes: 0

johannes
johannes

Reputation: 15989

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

Upvotes: 0

Related Questions