X509_CHECK_PRIVATE_KEY(3ossl)
π
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()andX509_REQ_check_private_key()do not check ifpkeyitself 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 π
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
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms