in reply to OT: PGP encryption command to use in Perl

I would use the -f command line option and use pgp as a filter:

my $cmd = "pgp -f -ea +batchmode publickey.pgp >SampleData.txt.asc"; open my $pgp, "| $cmd" or die "Couldn't run [$cmd]: $!"; print $pgp "Hello World"; close $pgp;

Replies are listed 'Best First'.
Re^2: OT: PGP encryption command to use in Perl
by newperlmonkey (Novice) on Oct 12, 2015 at 19:41 UTC
    When I run using '-f' argument, the cursor is just stuck there and doesnt do any thing.

    I tried the following and it worked but the description for 'w' scares me :(

    $encrytion = `pgp -eaw +batchmode $file publickey.pgp`;

    Description from Doc "This instructs PGP to create a ciphertext file “message.pgp”, and to destroy the plaintext file “message.txt”. Note that this option will not wipe out any fragments of plaintext that your word processor might have created on the disk while you were editing the message before running PGP. Most word processors create backup files, scratch files, or both. PGP overwrites the file 26 times."

    Is it safe to use the above command or does it do something funky and I'm better off issuing a separate delete command for the original file?

    Thank you for your help

      I couldn't test this and only showed you what I read from the manpage.

      Personally, I use a pipe through GPG like this:

      my $GPG_cmd = "/usr/bin/gpg --homedir . --keyring pubring.gpg --secret +-keyring secring.gpg --batch --trust-model always -z 7 --no-secmem-wa +rning --lock-never"; open my $gpg, qq(| $GPG_cmd --output "$OUTFILE") or die "Couldn't launch $GPG_cmd: $!"; print $gpg $mydata;
      Did you open it with
      open my $fh, "| pgp -f ..." or die ...
      or did you perhaps use the -f option with backticks?

      I don't know the specific version of pgp, Corion's seems to read from STDIN when -f is used, so this would just wait for your input from the keyboard (with backticks) instead of open "| ..." reading from the file handle.

      Update: Better style: Three argument form
      open my $fh, '|-', $cmd or die "failed to execute:\n\t$cmd\n$! +";
      References: qx and Quote Like Operators for backticks, Using open() for IPC for open