Skip to content
ecdsa.com
OpenSSL 3OpenSSL CLI

Error message

error:05800074:x509 certificate routines::key values mismatch

Also printed as

  • x509 certificate routines:ossl_x509_check_private_key:key values mismatch
  • [X509: KEY_VALUES_MISMATCH] key values mismatch
  • code: 'ERR_OSSL_X509_KEY_VALUES_MISMATCH'

nginx -t reports it as "[emerg] SSL_CTX_use_PrivateKey(\"<key file>\") failed (SSL: error:05800074:x509 certificate routines::key values mismatch)"; the openssl CLI adds the function name ("x509 certificate routines:ossl_x509_check_private_key:key values mismatch"); Python prints "[X509: KEY_VALUES_MISMATCH] key values mismatch"; Node.js sets code ERR_OSSL_X509_KEY_VALUES_MISMATCH. OpenSSL 1.1.1 used the code 0B080074.

OpenSSL 3 — X509_R_KEY_VALUES_MISMATCH when loading a certificate with a private key (nginx, Node.js, Python, openssl s_server)

What it means

A TLS server (or library) was given a certificate and a private key that do not belong together: the public key inside the certificate is not the public half of the private key. OpenSSL refuses to load the pair, so the server fails to start or the context cannot be created. Nothing is wrong with either file on its own.

Why it happens

How to fix it

  1. 1.

    Compare the public keys

    Hash the public key extracted from the certificate and the one derived from the private key; identical hashes mean they belong together. This works for RSA, EC and Ed25519 keys alike.

    bash
    # The two hashes must be identical
    openssl x509 -in server.pem -noout -pubkey | openssl sha256
    openssl pkey -in server.key -pubout | openssl sha256
  2. 2.

    Put the leaf first in the bundle

    List the subjects in the bundle; the leaf for your host name must come first, followed by intermediates.

    bash
    # Servers match the key against the FIRST certificate of the file: make it the leaf
    openssl crl2pkcs7 -nocrl -certfile fullchain.pem | openssl pkcs7 -print_certs -noout | grep subject=
    cat api.example.com.crt intermediate.crt > fullchain.pem
  3. 3.

    Find the matching key among several

    Compare the certificate's public-key hash with each candidate key; if none matches, the key was lost and the certificate has to be reissued with a new key.

    bash
    # Which of several keys belongs to the certificate?
    cert=$(openssl x509 -in server.pem -noout -pubkey | openssl sha256)
    for k in /etc/ssl/private/*.key; do
      [ "$(openssl pkey -in "$k" -pubout 2>/dev/null | openssl sha256)" = "$cert" ] && echo "match: $k"
    done

Related errors

Browse the full signature error database