Advertisement
Anakthewolf

OpenPGP

May 11th, 2014
400
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. # genera chiavi pubblica e privata di Crypt::OpenPGP
  6. # cifrare dati
  7. # decifrare dati
  8.  
  9. use Crypt::OpenPGP;
  10.  
  11. my $size  = '1024';
  12. my $ident = 'Mario Rossano <anak@cpan.org>';
  13. my $pass  = 'pippo';
  14. my $public_file  = 'public.pgp';
  15. my $private_file = 'private.pgp';
  16.  
  17. my $plainText='test';
  18.  
  19. my $keychain = Crypt::OpenPGP->new();
  20.  
  21. my ($public, $private) = $keychain->keygen (
  22.     Type => 'RSA',
  23.     Identity  => $ident,
  24.     Size      => $size,
  25.     Passphrase  => $pass,
  26.     Verbosity => 1,
  27. ) or die $keychain->errstr();
  28.  
  29. my $public_str = $public->save;
  30. my $private_str = $private->save;
  31.  
  32. print "Public encrypting_key: ".$public->encrypting_key ."\n";
  33. print "Private encrypting_key: ".$private->encrypting_key ."\n";
  34.  
  35. open my $fh,'>',$public_file or die $!;
  36.     print $fh $public_str;
  37. close $fh;
  38.  
  39. open $fh, '>', $private_file or die $!;
  40.     print $fh $private_str;
  41. close $fh;
  42.  
  43. my $pgp = Crypt::OpenPGP->new(
  44.     PubRing => $public_file,
  45.     SecRing => $private_file
  46. );
  47.  
  48. my $cyphertext = $pgp->encrypt (
  49.     Data    => $plainText,
  50.     Recipients => $ident
  51. ) or die $pgp->errstr();
  52.  
  53. print "testo criptato: ".$cyphertext;
  54.  
  55. my $decryptedText = $pgp->decrypt (
  56.     Data => $cyphertext,
  57.         Passphrase => $pass
  58. ) || die $pgp->errstr();
  59.  
  60. print "testo decriptato: ".$decryptedText."\n";
Advertisement
RAW Paste Data Copied
Advertisement