---
name: "X509_check_private_key"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/X509_check_private_key"
---

# X509\_check\_private\_key(3ssl)

check the consistency of a private key with the public key in an X509 certificate or certificate request

## NAME

X509\_check\_private\_key, X509\_REQ\_check\_private\_key - check the consistency of a private key with the public key in an X509 certificate or certificate request

## 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

**X509\_check\_private\_key()** function checks the consistency of private key *pkey* with the public key in *cert*.

**X509\_REQ\_check\_private\_key()** is equivalent to **X509\_check\_private\_key()** except that *req* represents a certificate request of structure **X509\_REQ**.

## RETURN VALUES

**X509\_check\_private\_key()** and **X509\_REQ\_check\_private\_key()** return 1 if the keys match each other, and 0 if not.

If the key is invalid or an error occurred, the reason code can be obtained using **ERR\_get\_error**(3).

## BUGS

The **X509\_check\_private\_key()** and **X509\_REQ\_check\_private\_key()** functions 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.

## SEE ALSO

**ERR\_get\_error**(3)

## 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\>.
