Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use feature 'say';
- use Crypt::RSA;
- # istanza oggetto Crypt::RSA
- my $rsa=Crypt::RSA->new();
- # Alice produce la sua chiave privata per decifrare e la chiave pubblica da distribuire per cifrare
- my ($public, $private) = $rsa->keygen (
- Size => 1024,
- Verbosity => 1
- ) or die $rsa->errstr();
- say '-> Chiavi privata e pubblica OK';
- my $plainText='RSA al WORKSHOP@UNINA2014';
- # Bob cripta il suo messaggio per Alice con la chiave pubblica che ha ricevuto
- say '-->Cifratura RSA in corso...';
- my $encryptedText = $rsa->encrypt (
- Message => $plainText,
- Key => $public
- ) or die $rsa->errstr();
- say '-->Cifratura RSA completata';
- #say $encryptedText."\n";
- # Alice con la sua chiave privata è la sola che può decriptare il messaggio che Bob le ha inviato
- say '-->Decifratura RSA in corso...';
- my $decryptedText = $rsa->decrypt (
- Cyphertext => $encryptedText,
- Key => $private
- ) or die $rsa->errstr();
- say '-->Decifratura RSA completata';
- say $decryptedText;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement