-
Notifications
You must be signed in to change notification settings - Fork 4
/
sbire_rsa_keygen.pl
executable file
·58 lines (46 loc) · 1.22 KB
/
sbire_rsa_keygen.pl
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
#!/usr/bin/perl
####################
#
# sbire_rsa_keygen.pl
#
# @Version 0.2
#
# NRPE plugins update/manage master script (keygen)
#
# Usage :
# sbire_keygen.pl
#
####################
use strict;
my $PATH=shift @ARGV;
$PATH="." unless defined $PATH;
my $pubkey = "$PATH/sbire_key.pub";
my $privkey = "$PATH/sbire_key.private";
die "$pubkey File already exist" if (-f $pubkey);
die "$privkey File already exist" if (-f $privkey);
use Crypt::RSA;
my $rsa = new Crypt::RSA;
$_=`hostname`; chomp;
my $identity = $_;
print "Generation...\n";
my ($public, $private) =
$rsa->keygen (
Identity => $identity,
Size => 1024,
) or die $rsa->errstr();
print "Conversion to hex.\n";
use bigint;
my ($n,$d,$e);
$\=$/;
$n = Math::BigInt->new($private->{'private'}->{'_n'});
$d = Math::BigInt->new($private->{'private'}->{'_d'});
$e = Math::BigInt->new($private->{'private'}->{'_e'});
open PUB, ">$pubkey" || die "Cannot open $pubkey for writing";
print PUB $e->as_hex();
print PUB $n->as_hex();
close PUB;
open PRI, ">$privkey" || die "Cannot open $privkey for writing";
print PRI $d->as_hex();
print PRI $n->as_hex();
close PRI;
print "Done\n";