diff --git a/RSA.pm b/RSA.pm index 4ce4b3b..838cb02 100644 --- a/RSA.pm +++ b/RSA.pm @@ -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__ @@ -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. Returns the same PKCS#1 +C PEM format (C). Provided for +naming symmetry with the import method C (which +auto-detects PKCS#1 vs X.509) and with C. + =item get_public_key_x509_string Return the Base64/DER-encoded representation of the "subject diff --git a/t/format.t b/t/format.t index 5dc6825..0f4f516 100644 --- a/t/format.t +++ b/t/format.t @@ -3,7 +3,7 @@ use Test::More; use Crypt::OpenSSL::RSA; -BEGIN { plan tests => 35 } +BEGIN { plan tests => 39 } my $PRIVATE_KEY_STRING = <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" );