Line | |
---|
1 | # A test for encryption (#27: https://forge.ipsl.jussieu.fr/epoll/ticket/27) |
---|
2 | |
---|
3 | use Crypt::RSA; # crypt/decrypt |
---|
4 | use XML::Simple; # dump data |
---|
5 | use MIME::Base64; # to make it ascii |
---|
6 | |
---|
7 | my $rsa = new Crypt::RSA ES => 'PKCS1v15'; |
---|
8 | |
---|
9 | my ($public, $private) = |
---|
10 | $rsa->keygen ( |
---|
11 | Identity => 'Vote ID 12', |
---|
12 | Size => 768, |
---|
13 | Password => undef, |
---|
14 | Verbosity => 0, |
---|
15 | KF=>'SSH', |
---|
16 | ) or die $rsa->errstr(); |
---|
17 | print $public->serialize; |
---|
18 | print "\n"; |
---|
19 | print encode_base64($private->serialize); |
---|
20 | print "\n"; |
---|
21 | my $xs = XML::Simple->new(ForceArray => 1, RootName => 'ballot'); |
---|
22 | print my $xml = $xs->XMLout({ id => '8daad55a7f94a4fb79bda7ab007953dc', sbal => [ 'coco', 'kikikikikikikikikikikikiki' ], fsbal => [] }); |
---|
23 | print "##########\n"; |
---|
24 | |
---|
25 | my $encryptedballot = $rsa->encrypt ( |
---|
26 | Message => $xml, |
---|
27 | Key => $public, |
---|
28 | Armour => 1, |
---|
29 | ) || die $rsa->errstr(); |
---|
30 | |
---|
31 | # reading |
---|
32 | print $encryptedballot . "\n"; |
---|
33 | |
---|
34 | my $ballot; |
---|
35 | foreach (0..1000) { |
---|
36 | $ballot = $rsa->decrypt( |
---|
37 | Cyphertext => $encryptedballot, |
---|
38 | Key => $private, |
---|
39 | Armour => 1, |
---|
40 | ) || die $rsa->errstr(); |
---|
41 | } |
---|
42 | |
---|
43 | print $ballot |
---|
44 | |
---|
Note: See
TracBrowser
for help on using the repository browser.