Q7898339
Q7898339

Reputation: 33

PHP/GnuPG Decryption -- Syntax error?

I'm using php to invoke gpg, but I'm getting a pipe error. I thought that if I read in the password from a file, I could then pipe it to the command itself? But, I keep getting: Syntax error: "|" unexpected

Here's the code:

(Note: The files are being iterated over in a foreach loop...)

foreach($files as $k => $v) {
    $encrypted = $v;
    $filename = explode('.',$v);
    $decrypted = $filename[0].'.txt';
    shell_exec("echo $passphrase | gpg --no-tty --passphrase-fd 0 -o $decrypted -d $encrypted");
}

Upvotes: 0

Views: 361

Answers (1)

catchmeifyoutry
catchmeifyoutry

Reputation: 7349

maybe you can print the lines instead and then run them in a terminal to see if they really work as expected. Maybe there is some weird character in your input that needs to be escaped, and please put your PHP variables in quotes, filenames with spaces could be dangerous. See escapeshellarg and escapeshellcmd.

Upvotes: 1

Related Questions