File: Parse.pm

package info (click to toggle)
libcrypt-rsa-parse-perl 0.044-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 140 kB
  • sloc: perl: 251; makefile: 2
file content (114 lines) | stat: -rw-r--r-- 2,947 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package Crypt::RSA::Parse;

use strict;
use warnings;

our $VERSION = 0.044;

=pod

=encoding utf-8

=head1 NAME

Crypt::RSA::Parse - Parse RSA keys

=head1 SYNOPSIS

    #General-purpose, native RSA or PKCS8 (DER or PEM)
    my $public_rsa = Crypt::RSA::Parse::public($key_str);
    my $private_rsa = Crypt::RSA::Parse::private($private_key_str);

    $public_rsa->exponent();    #alias E()
    $public_rsa->modulus();     #isa Math::BigInt, alias N()
    $public_rsa->size();        #i.e., the modulus length in bits

    $private_rsa->version();        #usually 0
    $private_rsa->modulus();        #isa Math::BigInt, alias N()
    $private_rsa->size();           #i.e., the modulus length in bits

    $private_rsa->publicExponent();     #same as public “exponent”, alias E()
    $private_rsa->privateExponent();    #isa Math::BigInt, alias D()
    $private_rsa->prime1();             #isa Math::BigInt, alias P()
    $private_rsa->prime2();             #isa Math::BigInt, alias Q()
    $private_rsa->exponent1();          #isa Math::BigInt, alias DP()
    $private_rsa->exponent2();          #isa Math::BigInt, alias DQ()
    $private_rsa->coefficient();        #isa Math::BigInt, alias QINV()

    #Only checks PKCS8 (DER or PEM)
    $public_rsa = Crypt::RSA::Parse::public_pkcs8($pkcs8_str);
    $private_rsa = Crypt::RSA::Parse::private_pkcs8($pkcs8_str);

    {
        #If, for whatever reason, you don’t like MIME::Base64,
        #then customize this. The module must have a decode() function.
        #
        local $Crypt::RSA::Parse::BASE64_MODULE = '..';

        Crypt::RSA::Parse::...
    }

=head1 DEPRECATION NOTICE

B<IMPORTANT:> This distribution is no longer maintained. See its successor,
L<Crypt::Perl>, for a much more comprehensive toolkit.

=head1 DESCRIPTION

Not much else to say: it parses RSA keys for useful information!

The public keys are represented via the C<Crypt::RSA::Parse::Public>
class, while private keys are represented via C<Crypt::RSA::Parse::Private>.

=cut

use Crypt::Format ();

use Crypt::RSA::Parse::Parser::MathBigInt ();   #lazy-loads Math::BigInt only

our $BASE64_MODULE = 'MIME::Base64';

my %parser;

sub _MathBigInt {
    return $parser{'MathBigInt'} ||= Crypt::RSA::Parse::Parser::MathBigInt->new();
}

sub private {
    return _MathBigInt()->private(@_);
}

sub public {
    return _MathBigInt()->public(@_);
}

sub private_pkcs8 {
    return _MathBigInt()->private_pkcs8(@_);
}

sub public_pkcs8 {
    return _MathBigInt()->public_pkcs8(@_);
}

#----------------------------------------------------------------------

=head1 AUTHOR

    Felipe M. L. Gasper
    CPAN ID: FELIPE

=head1 REPOSITORY

    https://github.com/FGasper/p5-Crypt-RSA-Parse

=head1 COPYRIGHT

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut

1;