#!/usr/bin/perl use strict; use warnings; use File::Basename; use Crypt::OpenPGP; my $ring = Crypt::OpenPGP::KeyRing->new( Data => qq^-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.8 (SunOS) mQGiBFDr..... -----END PGP PUBLIC KEY BLOCK-----^ ); my $datafile = "original.csv"; # Get just name of the original file to name the new encrypted file. my ( $encrypted ) = fileparse( $datafile, '\.[^.]*' ); # $name, $path, $suffix open( my $in, "<", $datafile ) or die "Could not open csv file - $!"; my $plaintext = do{local $/;<$in>}; close $in; $ring->read; my $kb = $ring->find_keyblock_by_index(0); my $cert = $kb->encrypting_key; my $pgp = Crypt::OpenPGP->new( Compat => 'GnuPG' ); my $ct = $pgp->encrypt( Key => $cert, Data => $plaintext, Armour => 1 ) or die "ERROR: " . $pgp->errstr; open( my $out, ">", "$encrypted.pgp" ) or die "Could not open file for encrypted data - $!"; print $out $ct; close $out;