source: branches/1/sandbox/encryption.pl @ 442

Last change on this file since 442 was 155, checked in by nanardon, 15 years ago
  • tag 1.00
File size: 1.2 KB
Line 
1# A test for encryption (#27: https://forge.ipsl.jussieu.fr/epoll/ticket/27)
2
3use Crypt::RSA; # crypt/decrypt
4use XML::Simple; # dump data
5use MIME::Base64; # to make it ascii
6
7my $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();
17print $public->serialize;
18print "\n";
19print encode_base64($private->serialize);
20print "\n";
21my $xs = XML::Simple->new(ForceArray => 1, RootName => 'ballot');
22print my $xml = $xs->XMLout({ id => '8daad55a7f94a4fb79bda7ab007953dc', sbal => [ 'coco', 'kikikikikikikikikikikikiki' ], fsbal => [] });
23print "##########\n";
24
25my $encryptedballot = $rsa->encrypt ( 
26            Message    => $xml,
27            Key        => $public,
28            Armour     => 1,
29        ) || die $rsa->errstr();
30
31# reading
32print $encryptedballot . "\n";
33
34my $ballot;
35foreach (0..1000) {
36$ballot = $rsa->decrypt(
37        Cyphertext => $encryptedballot,
38            Key        => $private,
39            Armour     => 1,
40        ) || die $rsa->errstr();
41}
42
43print $ballot
44
Note: See TracBrowser for help on using the repository browser.