blob: 4db25036456a1a1601e71dad279d82afd7e6c6ed (
plain)
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
|
package Crypt::OpenPGP::Key::Secret::RSA;
use strict;
use Crypt::RSA::Key::Private;
use Crypt::OpenPGP::Key::Public::RSA;
use Crypt::OpenPGP::Key::Secret;
use Crypt::OpenPGP::Util qw( bin2mp );
use Crypt::OpenPGP::ErrorHandler;
use base qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
sub secret_props { qw( d p q u ) }
*sig_props = \&Crypt::OpenPGP::Key::Public::RSA::sig_props;
*public_props = \&Crypt::OpenPGP::Key::Public::RSA::public_props;
*crypt_props = \&Crypt::OpenPGP::Key::Public::RSA::crypt_props;
*size = \&Crypt::OpenPGP::Key::Public::RSA::size;
*encode = \&Crypt::OpenPGP::Key::Public::RSA::encode;
*keygen = \&Crypt::OpenPGP::Key::Public::RSA::keygen;
*can_encrypt = \&Crypt::OpenPGP::Key::Public::RSA::can_encrypt;
*can_sign = \&Crypt::OpenPGP::Key::Public::RSA::can_sign;
sub init {
my $key = shift;
$key->{key_data} = shift ||
Crypt::RSA::Key::Private->new( Password => 'pgp' );
$key;
}
*encrypt = \&Crypt::OpenPGP::Key::Public::RSA::encrypt;
sub decrypt {
my $key = shift;
my($C) = @_;
require Crypt::RSA::Primitives;
my $prim = Crypt::RSA::Primitives->new;
$prim->core_decrypt( Key => $key->{key_data}, Cyphertext => $C->{c} );
}
sub sign {
my $key = shift;
my($dgst, $hash_alg) = @_;
my $m = encode($dgst, $hash_alg, $key->bytesize - 1);
require Crypt::RSA::Primitives;
my $prim = Crypt::RSA::Primitives->new;
$m = bin2mp($m);
my $c = $prim->core_sign( Key => $key->{key_data}, Message => $m );
{ c => $c }
}
1;
|