By: Darrell Brogdon Printer Friendly Format
$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");
This script tells gpg to accept the passphrase from STDIN (indicated by the 0 following the switch) and decrypt the information into a file named "foo.txt".
As with encrypting information, you can leave off the -oswitch to gpg and let the decrypted data be captured inside a variable.
It should be noted that the -o switch should always come before the -d switch.
Most Viewed Articles (in PHP )
Latest Articles (in PHP)
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews