| 1 | package Crypt::Perl::RSA; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | =encoding utf-8 | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Crypt::Perl::RSA - RSA in pure Perl (really!) | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | my $prkey1 = Crypt::Perl::RSA::Parse::private($pem_or_der); | ||
| 15 | my $pbkey1 = Crypt::Perl::RSA::Parse::public($pem_or_der); | ||
| 16 | |||
| 17 | #---------------------------------------------------------------------- | ||
| 18 | |||
| 19 | my $prkey = Crypt::Perl::RSA::Generate::generate(2048); | ||
| 20 | |||
| 21 | my $der = $prkey->to_der(); | ||
| 22 | my $der2 = $prkey->to_pem(); | ||
| 23 | |||
| 24 | #---------------------------------------------------------------------- | ||
| 25 | |||
| 26 | my $msg = 'My message'; | ||
| 27 | |||
| 28 | my $sig = $prkey->sign_RS256($msg); | ||
| 29 | |||
| 30 | die 'Wut' if !$prkey->verify_RS256($msg, $sig); | ||
| 31 | |||
| 32 | die 'Wut' if !$pbkey->verify_RS256($msg, $sig); | ||
| 33 | |||
| 34 | =head1 DISCUSSION | ||
| 35 | |||
| 36 | See the documentation for L<Crypt::Perl::RSA::PublicKey> and | ||
| 37 | L<Crypt::Perl::RSA::PrivateKey> for more on what these interfaces | ||
| 38 | can do. | ||
| 39 | |||
| 40 | NOTE: The RSA logic here is ported from Kenji Urushima’s | ||
| 41 | L<jsrsasign|http://kjur.github.io/jsrsasign/>. | ||
| 42 | |||
| 43 | =head1 SECURITY | ||
| 44 | |||
| 45 | RSA is safe as long as factorization is “hard”. As computers get faster, RSA | ||
| 46 | keys have needed to get bigger and bigger to maintain the “difficulty” of | ||
| 47 | factoring the key’s modulus. RSA will eventually no longer be viable toward | ||
| 48 | this end: as RSA keys get bigger, the | ||
| 49 | security advantage of increasing their size diminishes. | ||
| 50 | |||
| 51 | =head1 SPEED | ||
| 52 | |||
| 53 | Key generation is probably generally useful only with an XS-based backend to | ||
| 54 | L<Math::BigInt>. Once L<Math::Prime::Util> is installable without a compiler | ||
| 55 | I’ll replace L<Math::ProvablePrime> here with Math::Prime::Util, which should | ||
| 56 | speed things up significantly. | ||
| 57 | |||
| 58 | =head1 TODO | ||
| 59 | |||
| 60 | This minimal set of functionality can be augmented as feature requests come in. | ||
| 61 | Ideas: | ||
| 62 | |||
| 63 | =over 4 | ||
| 64 | |||
| 65 | =item * Support signature schemes besides PKCS #1 v1.5. | ||
| 66 | |||
| 67 | =item * Use faster prime-number-finder logic if it’s available. | ||
| 68 | |||
| 69 | =back | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | 1; |