I have looked all over and have yet to find an example of the key for
the key_string parameter. I have tried many different openssl public
keys and all of them fail with the wrong format. The documentation says "
new_public_key
Create a new Crypt::OpenSSL::RSA object by loading a public key in
from a string containing Base64/DER-encoding of either the PKCS1 or
X.509 representation of the key. The string should include the
-----BEGIN...----- and -----END...----- lines.
The padding is set to PKCS1_OAEP, but can be changed with the
use_xxx_padding methods
new_private_key
Create a new Crypt::OpenSSL::RSA object by loading a private key in
from an string containing the Base64/DER encoding of the PKCS1
representation of the key. The string should include the
-----BEGIN...----- and -----END...----- lines. The padding is set to
PKCS1_OAEP, but can be changed with use_xxx_padding.
"
What is the openssl command to generate the public and private keys
needed for the following script:
use Crypt::OpenSSL::Random; use Crypt::OpenSSL::RSA; # not necessary if
we have /dev/random: Crypt::OpenSSL::Random::random_seed($good_entropy);
Crypt::OpenSSL::RSA->import_random_seed(); $rsa_pub =
Crypt::OpenSSL::RSA->new_public_key($key_string);
$rsa_pub->use_sslv23_padding(); # use_pkcs1_oaep_padding is the default
$ciphertext = $rsa->encrypt($plaintext); $rsa_priv =
Crypt::OpenSSL::RSA->new_private_key($key_string); $plaintext =
$rsa->encrypt($ciphertext); $rsa =
Crypt::OpenSSL::RSA->generate_key(1024); # or $rsa =
Crypt::OpenSSL::RSA->generate_key(1024, $prime); print "private key
is:\n", $rsa->get_private_key_string(); print "public key (in PKCS1
format) is:\n", $rsa->get_public_key_string(); print "public key (in
X509 format) is:\n", $rsa->get_public_key_x509_string();
$rsa_priv->use_md5_hash(); # use_sha1_hash is the default $signature =
$rsa_priv->sign($plaintext); print "Signed correctly\n" if
($rsa->verify($plaintext, $signature));
Thanks.
--
Daniel Campbell
Director of Networking
On2 Technologies
|