Crypt-OpenSSL-RSA

 view release on metacpan or  search on metacpan

t/rsa.t  view on Meta::CPAN

use Crypt::OpenSSL::RSA;
use Crypt::OpenSSL::Guess qw(openssl_version);

BEGIN {
    plan tests => 37 + ( UNIVERSAL::can( "Crypt::OpenSSL::RSA", "use_sha512_hash" ) ? 4 * 5 : 0 ) + ( UNIVERSAL::can( "Crypt::OpenSSL::RSA", "use_whirlpool_hash" ) ? 1 * 5 : 0 );
}

sub _Test_Encrypt_And_Decrypt {
    my ( $p_plaintext_length, $p_rsa, $p_check_private_encrypt ) = @_;

    my ( $ciphertext, $decoded_text );
    my $plaintext = pack(
        "C${p_plaintext_length}",
        (
            1, 255, 0, 128, 4,    # Make sure these characters work
            map { int( rand 256 ) } ( 1 .. $p_plaintext_length - 5 )
        )
    );
    ok( $ciphertext   = $p_rsa->encrypt($plaintext) );
    ok( $decoded_text = $p_rsa->decrypt($ciphertext) );
    ok( $decoded_text eq $plaintext );

    if ($p_check_private_encrypt) {
        ok( $ciphertext   = $p_rsa->private_encrypt($plaintext) );
        ok( $decoded_text = $p_rsa->public_decrypt($ciphertext) );
        ok( $decoded_text eq $plaintext );
    }
}

sub _Test_Sign_And_Verify {
    my ( $plaintext, $rsa, $rsa_pub, $hash ) = @_;

    my $sig = eval { $rsa->sign($plaintext) };
  SKIP: {
        skip "OpenSSL error: illegal or unsupported padding mode - $hash", 5 if $@ =~ /illegal or unsupported padding mode/i;
        ok( $rsa_pub->verify( $plaintext, $sig ) );



( run in 0.314 second using v1.01-cache-2.11-cpan-26ccb49234f )