X509_CHECK_PRIVATE_KEY(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… X509_check_private_key, X509_REQ_check_private_key β€” like, do these two keys actually belong together?? (the 3ossl girlies know) πŸ”‘

Okay bestie, so this is the 3ossl manual page for X509_check_private_key and X509_REQ_check_private_key, and honestly? It's giving "are you two actually dating or just holding hands for the photos." Let's get into it πŸ’–


✨ NAME ✨

X509_check_private_key, X509_REQ_check_private_key β€” these check that a private key is consistent with the public key inside an X509 certificate or a certificate request. Basically a vibe check but for key pairs πŸŽ€


🌸 SYNOPSIS 🌸

#include <openssl/x509.h>

int X509_check_private_key(const X509 *cert, EVP_PKEY *pkey);

int X509_REQ_check_private_key(X509_REQ *req, EVP_PKEY *pkey);

πŸ¦‹ DESCRIPTION πŸ¦‹

So X509_check_private_key() checks the consistency of the private key pkey with the public key in cert. Like, are these two actually a matching set or is somebody catfishing πŸ’€

And X509_REQ_check_private_key() is literally the same thing, except req represents a certificate request of structure X509_REQ. Same energy, different struct, no cap 🫢


🌈 RETURN VALUES 🌈

Both X509_check_private_key() and X509_REQ_check_private_key() return 1 if the keys match each other, and 0 if they don't. It's giving yes/no, slay/flop, matched/it's complicated πŸ’…

If the key is invalid or an error occurred, you can get the reason code using ERR_get_error(3). That's your receipts, bestie 🧾✨


πŸ’€ BUGS πŸ’€

Not me having to tell you this but β€” X509_check_private_key() and X509_REQ_check_private_key() do not check if pkey itself is indeed a private key or not.

They merely compare the public materials (e.g., exponent and modulus of an RSA key) and/or key parameters (e.g. EC params of an EC key) of a key pair. So they also return success if pkey is a matching public key 😭

Translation: this function is checking chemistry, not identity. It'll say "yes these match" even if the second one is a whole public key. So don't @ me when your "private key" check passes and it was public the whole time. Fr fr, lowkey iconic behavior, highkey a footgun πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘


Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


And that's the whole page, bestie πŸ“ This drop is 3.5.6, dated 2026-04-07, from the X509_CHECK_PRIVATE_KEY(3ossl) girlies themselves β€” go forth and verify those key pairs responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from