gnutls_certificate_set_key - Linux


Overview

gnutls_certificate_set_key allows the user to set the private key of an X.509 certificate. This is typically used to load the private key for a server certificate.

Syntax

gnutls_certificate_set_key(certificate, key)

Parameters

  • certificate: The certificate to set the private key for.
  • key: The private key to set.

Options/Flags

None.

Examples

Setting a private key from a file

gnutls_certificate_set_key(certificate, gnutls_privkey_load_file("server.pem", GNUTLS_X509_FMT_PEM))

Setting a private key from a memory buffer

gnutls_certificate_set_key(certificate, gnutls_privkey_import_pkcs8(key_buffer, key_len, GNUTLS_PRIVKEY_FMT_PKCS8))

Common Issues

Unable to load private key

Make sure that the private key is in a supported format and that the correct password is being provided.

Certificate and private key do not match

The private key and certificate must be for the same entity. Check that the certificate and private key are from the same source.

Integration

gnutls_certificate_set_key is often used in conjunction with other GNUTLS functions, such as gnutls_certificate_allocate() and gnutls_certificate_sign().

Related Commands