#!/usr/bin/perl # gpg.pl use Crypt::OpenPGP; my $string = $ARGV[0]; my $pgp = Crypt::OpenPGP->new; my $ciphertext = $pgp->encrypt( Data => $string, Recipients => 'Test User', Armour => 1, ); open(OUT, ">testfile"); print OUT $ciphertext, "\n"; close(OUT); #### #!/usr/bin/perl # gupg.pl use Crypt::OpenPGP; my $pgp = Crypt::OpenPGP->new; my ($plaintext) = $pgp->decrypt( Filename => 'testfile', Passphrase => 'password', ); die "Decryption failed: ", $pgp->errstr unless $plaintext; print $plaintext, "\n"; #### #!/usr/bin/perl # gpg.pl use Crypt::OpenPGP; use DBI; my $string = $ARGV[0]; my $dbh = DBI->connect("DBI:mysql:pgpdb:localhost","user","password"); my $insert_stmt = 'insert into pgptable (card) values (?)'; my $sth = $dbh->prepare($insert_stmt); my $pgp = Crypt::OpenPGP->new; my $ciphertext = $pgp->encrypt( Data => $string, Recipients => 'Test User', Armour => 1, ); $sth->execute($ciphertext) || die $dbh->stderr; #### #!/usr/bin/perl # gupg.pl use Crypt::OpenPGP; use DBI; my $dbh = DBI->connect("DBI:mysql:pgpdb:localhost","user","password"); my $select_query = 'select card from pgptable where id=?'; my $sth = $dbh->prepare($select_query); my $pgp = Crypt::OpenPGP->new; $sth->execute('1') || die $dbh->stderr; my $data = ($sth->fetchrow_hashref)->{'card'}; my ($plaintext) = $pgp->decrypt( Data => $data, Passphrase => 'passphrase', ); die "Decryption failed: ", $pgp->errstr unless $plaintext; print $plaintext, "\n";