Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- # genera chiavi pubblica e privata di Crypt::OpenPGP
- # cifrare dati
- # decifrare dati
- use Crypt::OpenPGP;
- my $size = '1024';
- my $pass = 'pippo';
- my $public_file = 'public.pgp';
- my $private_file = 'private.pgp';
- my $plainText='test';
- my $keychain = Crypt::OpenPGP->new();
- my ($public, $private) = $keychain->keygen (
- Type => 'RSA',
- Identity => $ident,
- Size => $size,
- Passphrase => $pass,
- Verbosity => 1,
- ) or die $keychain->errstr();
- my $public_str = $public->save;
- my $private_str = $private->save;
- print "Public encrypting_key: ".$public->encrypting_key ."\n";
- print "Private encrypting_key: ".$private->encrypting_key ."\n";
- open my $fh,'>',$public_file or die $!;
- print $fh $public_str;
- close $fh;
- open $fh, '>', $private_file or die $!;
- print $fh $private_str;
- close $fh;
- my $pgp = Crypt::OpenPGP->new(
- PubRing => $public_file,
- SecRing => $private_file
- );
- my $cyphertext = $pgp->encrypt (
- Data => $plainText,
- Recipients => $ident
- ) or die $pgp->errstr();
- print "testo criptato: ".$cyphertext;
- my $decryptedText = $pgp->decrypt (
- Data => $cyphertext,
- Passphrase => $pass
- ) || die $pgp->errstr();
- print "testo decriptato: ".$decryptedText."\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement