1

I am trying to use the right library to make the following two calls in perl:

openssl x509 -noout -modulus -in server.crt | openssl md5

openssl rsa -noout -modulus -in server.key | openssl md5

Are these the best options: CPAN_Crypt_OpenSSL_X509 CPAN_Crypt_OpenSSL_RSA

or can it be done in: Net::SSLeay ?

A pointer to an example will surely help.

4
  • These commands do not make much sense for me. What you are trying to get with these commands? Dec 3, 2014 at 8:50
  • If your objective is to check if the private key matches the public key in the certificate you can simply use them together to built a test server. Apart from that Crypt::OpenSSL::X509 has a modules function and Crypt::OpenSSL::RSA a get_key_parameters which might help you. Dec 9, 2014 at 5:20
  • without actually bringing up a server I wanted to validate these and thats the reason I asked.
    – newnovice
    Dec 9, 2014 at 23:34

1 Answer 1

0

You could just compare the hex strings of the moduli to achieve the same result, without doing a digest. Crypt::OpenSSL::X509 and Crypt::OpenSSL::RSA have the necessary methods to do this:

my $x509_cert = Crypt::OpenSSL::X509->new_from_string('...');
my $pkey = Crypt::OpenSSL::RSA->new_private_key('...');

my ($key_modulus) = $pkey->get_key_parameters;
if ($x509_cert->modulus eq $key_modulus->to_hex) {
  # same modulus
}
else {
  # different
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.