1#!/usr/bin/env perl 2use strict; 3use warnings; 4 5use Test::More; 6use Crypt::RSA::Key; 7use Data::Dumper; 8 9plan tests => 1*2; 10 11# Danaj: This is definitely not the interface I would have chosen. It would 12# seem like you'd like to be able to hand the string to generate. 13# Why do I have to make a full new object to deserialize? 14 15my $obj = new Crypt::RSA::Key; 16 17my ($pub, $pri) = $obj->generate( 18 Identity => 'Some User <someuser@example.com>', 19 Password => 'guess', 20 Size => 512, 21 KF => 'SSH', 22 ); 23my $n1 = $pri->n; 24 25# You can also use IDEA, DES, DES3, Twofish2, CAST5, Rijndael, RC6, Camellia. 26# Only Blowfish is required to be present based on the dependencies we list. 27foreach my $cipher (qw/Blowfish/) { 28 29 my $s = $pri->serialize( Cipher => $cipher, Password => 'serpent' ); 30 31 my ($newpub, $newpri) = $obj->generate( Size => 128, KF => 'SSH', ); 32 33 # Do it incorrectly first. Should croak. 34 eval { $newpri->deserialize( String => $s, Password => "mst" ); }; 35 like($@, qr/passphrase/i, "Bad passphrase will croak"); 36 37 $newpri->deserialize( String => $s, Password => "serpent" ); 38 # newpri should have no password assigned 39 $newpri->{Password} = 'guess'; 40 41 is_deeply( $newpri, $pri, "private key fully deserialized using $cipher"); 42 43} 44