crypt_rsa.pl 951 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/perl
  2. # Using Crypt::RSA with a specific private key.
  3. use 5.014;
  4. use Crypt::RSA;
  5. my $rsa = Crypt::RSA->new;
  6. my $key = Crypt::RSA::Key->new;
  7. my ($public, $private) =
  8. $key->generate(
  9. p => "94424081139901371883469166542407095517576260048697655243",
  10. q => "79084622052242264844238683495727691663247340251867615781",
  11. e => 65537,
  12. )
  13. or die "error";
  14. my $cyphertext = $rsa->encrypt(
  15. Message => "Hello world!",
  16. Key => $public,
  17. Armour => 1,
  18. )
  19. || die $rsa->errstr();
  20. say $cyphertext;
  21. my $plaintext = $rsa->decrypt(
  22. Cyphertext => $cyphertext,
  23. Key => $private,
  24. Armour => 1,
  25. )
  26. || die $rsa->errstr();
  27. say $plaintext;