CURLOPT_SSLKEYTYPE(3)

πŸ’… CURLOPT_SSLKEYTYPE(3) πŸ’…

okay so this is from the Library Functions Manual bestie, and it's literally all about telling curl what format your private key file is in πŸ”‘


✨ NAME ✨

CURLOPT_SSLKEYTYPE β€” the type of the private key file, like, what flavor your key is πŸ“


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSLKEYTYPE, char *type);

πŸ¦‹ DESCRIPTION πŸ¦‹

You pass in a pointer to a null-terminated string as the parameter, and that string should be the format of your private key, no cap. The supported formats are "PEM", "DER", "ENG" and "PROV" ✨

The "ENG" format is what lets you load the private key from a crypto engine β€” very main character energy tbh. When you do that, CURLOPT_SSLKEY(3) gets used as an identifier that's passed to the engine, and you have to set the crypto engine with CURLOPT_SSLENGINE(3) πŸ’…

The "PROV" format lets you load the private key from a crypto provider (this was added in 8.12.0, iykyk). Same deal here: CURLOPT_SSLKEY(3) is used as an identifier passed to the provider 🫢

⚠️ Heads up bestie: the "DER" format does not work with OpenSSL. Not me warning you twice, but like… it doesn't.

Good news though β€” your application does not have to keep the string around after setting this option, so you can yeet it as soon as you're done 😌

And if you use this option multiple times? The last set string overrides the previous ones, periodt. Set it to NULL to restore the internal default πŸ’–


πŸ‘‘ DEFAULT πŸ‘‘

"PEM" β€” the standard, the icon, the moment ⭐


🌈 PROTOCOLS 🌈

This functionality affects all TLS based protocols, fr fr: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. 🌸

This option works only with the following TLS backends: OpenSSL and wolfSSL β€” that's the vibe check and those two passed 🧚


🌸 EXAMPLE 🌸

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
    curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
    curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
    curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

look at that little certified slay of a program πŸ”₯


⭐ AVAILABILITY ⭐

Added in curl 7.9.3 β€” she's been around for a minute, an absolute veteran πŸ’œ


πŸ’€ RETURN VALUE πŸ’€

curl_easy_setopt(3) returns a CURLcode that indicates success or error, that's it, that's the whole thing πŸ™ˆ

CURLE_OK (0) means everything was OK 😭❀️, and non-zero means an error occurred β€” go check libcurl-errors(3) for the deets.


🫢 SEE ALSO 🫢

go read those next bestie, they're all connected, it's giving lore πŸ¦‹


mwah πŸ’‹ that's the whole page β€” brought to you by libcurl, dated 2026-10-12, and yes that date is in the future, don't question it, she's iconic like that 🌟

πŸ“¦ where this page comes from