Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions RSA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ sub get_key_parameters {
return map { $_ ? Crypt::OpenSSL::Bignum->bless_pointer($_) : undef } shift->_get_key_parameters();
}

*get_public_key_pkcs1_string = \&get_public_key_string;

1;

__END__
Expand Down Expand Up @@ -197,6 +199,13 @@ header and footer lines:
-----BEGIN RSA PUBLIC KEY------
-----END RSA PUBLIC KEY------

=item get_public_key_pkcs1_string

Alias for C<get_public_key_string>. Returns the same PKCS#1
C<RSAPublicKey> PEM format (C<BEGIN RSA PUBLIC KEY>). Provided for
naming symmetry with the import method C<new_public_key> (which
auto-detects PKCS#1 vs X.509) and with C<get_public_key_x509_string>.

=item get_public_key_x509_string

Return the Base64/DER-encoded representation of the "subject
Expand Down
8 changes: 7 additions & 1 deletion t/format.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use Test::More;

use Crypt::OpenSSL::RSA;

BEGIN { plan tests => 35 }
BEGIN { plan tests => 39 }

my $PRIVATE_KEY_STRING = <<EOF;
-----BEGIN RSA PRIVATE KEY-----
Expand Down Expand Up @@ -78,6 +78,12 @@ ok( $public_key = Crypt::OpenSSL::RSA->new_public_key($PUBLIC_KEY_X509_STRING),
is( $public_key->get_public_key_string(), $PUBLIC_KEY_PKCS1_STRING, "X509 key exports to PKCS1 correctly" );
is( $public_key->get_public_key_x509_string(), $PUBLIC_KEY_X509_STRING, "X509 public key round-trips" );

# get_public_key_pkcs1_string is an alias for get_public_key_string
is( $private_key->get_public_key_pkcs1_string(), $PUBLIC_KEY_PKCS1_STRING, "get_public_key_pkcs1_string returns PKCS1 from private key" );
is( $public_key->get_public_key_pkcs1_string(), $PUBLIC_KEY_PKCS1_STRING, "get_public_key_pkcs1_string returns PKCS1 from public key" );
is( $private_key->get_public_key_pkcs1_string(), $private_key->get_public_key_string(), "pkcs1 alias matches get_public_key_string on private key" );
ok( $public_key = Crypt::OpenSSL::RSA->new_public_key($private_key->get_public_key_pkcs1_string()), "new_public_key accepts output of get_public_key_pkcs1_string" );

my $passphase = '123456';
ok( $private_key = Crypt::OpenSSL::RSA->new_private_key( $ENCRYPT_PRIVATE_KEY_STRING, $passphase ), "load encrypted private key" );
is( $private_key->get_private_key_string(), $DECRYPT_PRIVATE_KEY_STRING, "encrypted key decrypts to expected private key" );
Expand Down
Loading