In the answer from this question Determine if private key belongs to certificate?

The proposed solution is to match a private key and a certificate by extracting and matching the public key of both.

While in this page: https://www.sslshopper.com/certificate-key-matcher.html

The proposed solution is to extract the modulus of the public key, apply a MD5 hash to it and then compare the hashes.

Is there any difference in both approaches ? Would the second approach be the same if I compare only the modulus of the public key and not the MD5 hash ?

2 Answers 2


Well, yes. There is a difference between the approaches.

The approach described in Determine if private key belongs to certificate? uses the RSA cryptosystem, which is based on the factorization of large prime numbers and an information trapdoor using the modulus function. Yet, the same general approach may be used to orther public key cryptosystems (any scheme that has a difficult mathematical problem plus a trapdoor function can be a public key cryptosystem, e.g. you have the ElGamal scheme).

The solution proposed by sslhopper is limited to the RSA scheme (or any other scheme that uses the modulus function as the information trapdoor). If you look in the openssl manuals the -modulus option only exists in man rsa.

In summary, the first approach is more generic than the second. This is because any asymmetric encryption scheme must be capable of generating the public key from the private key, but not every scheme must use the modulus function as the information trapdoor.


In addition to @grochmal's point, if you're matching the public keys, then there is no way that a hash function vulnerability can affect you. It is probably also slightly faster to compare the bits directly, rather than hashing them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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