PKCS12_CREATE(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– PKCS12_CREATE(3) πŸ’–

ok so bestie, this is a page from the Library Functions Manual and honestly? it's giving crypto-baddie realness πŸ”₯. we're talking about PKCS12_create β€” the glow-up function that bundles your keys and certs into one iconic little .p12 package. let's get into it πŸŽ€


🌸 NAME 🌸

PKCS12_create β€” create a PKCS#12 structure ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

library β€œlibcrypto” #include <openssl/pkcs12.h>

PKCS12 *
PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
    X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter,
    int mac_iter, int keytype);

like, that's a lot of arguments bestie, but don't panic, we're gonna walk through every single one 🫢


✨ DESCRIPTION ✨

PKCS12_create() creates a PKCS#12 structure. that's the whole vibe. it's the builder function, the main character of the PKCS#12 universe πŸ‘‘

here's the tea on every parameter:

  • pass β€” the passphrase to use. keep it secret, keep it safe πŸ’…
  • name β€” the friendlyName to use for the supplied certificate and key. literally the nickname of your cert/key combo.
  • pkey β€” the private key to include in the structure.
  • cert β€” its corresponding certificates.
  • ca β€” an optional set of certificates to also include in the structure (choose your squad).
  • so pkey, cert, or both can be NULL to indicate that no key or certificate is required. no key? no cert? no problem, it's valid 🌈

πŸŽ€ encryption params πŸŽ€

  • nid_key and nid_cert are the encryption algorithms that should be used for the key and the certificate, respectively.
  • if either nid_key or nid_cert is set to -1, no encryption will be used. (ngl, that's the bold choice πŸ‘€)

🧚 iteration counts 🧚

  • iter is the encryption algorithm iteration count to use.
  • mac_iter is the MAC iteration count to use.
  • if mac_iter is set to -1, the MAC will be omitted entirely. periodt.

πŸ”₯ keytype πŸ”₯

  • keytype is the type of key.

⭐ the defaults ⭐

okay so the parameters nid_key, nid_cert, iter, mac_iter, and keytype can all be set to zero and sensible defaults will be used. slay, lazy-girl-friendly defaults πŸ’…

these defaults are:

  • 40-bit RC2 encryption for certificates
  • triple DES encryption for private keys
  • a key iteration count of PKCS12_DEFAULT_ITER (currently 2048)
  • a MAC iteration count of 1

so why is the default MAC iteration count literally 1? because compatibility, bestie 😭. it's that low in order to retain compatibility with old software which did not interpret MAC iteration counts. if such compatibility is not required then mac_iter should be set to PKCS12_DEFAULT_ITER. like, do the upgrade if you can, iykyk.

πŸ’€ keytype lore πŸ’€

keytype adds a flag to the store private key. heads up: this is a non-standard extension that is only currently interpreted by MSIE. it's giving ancient browser energy πŸ™ˆ

  • if set to zero, the flag is omitted
  • if set to KEY_SIG, the key can be used for signing only
  • if set to KEY_EX, it can be used for signing and encryption

this option was useful for old export grade software which could use signing only keys of arbitrary size but had restrictions on the permissible sizes of keys which could be used for encryption. history lesson, but make it crypto πŸ›οΈ

🌟 one last detail 🌟

if a certificate contains an alias or keyid then this will be used for the corresponding friendlyName or localKeyID in the PKCS12 structure. it just knows, okay? it knows ✨


🌈 RETURN VALUES 🌈

  • PKCS12_create() returns a valid PKCS12 structure on success πŸ‘‘
  • or NULL if an error occurred πŸ’€

literally that simple. check your returns, bestie, always 🫢


πŸ’œ SEE ALSO πŸ’œ

the whole friend group, go read them too πŸ§šβ€β™€οΈ


πŸ“ HISTORY πŸ“

PKCS12_create() first appeared in OpenSSL 0.9.3 and has been available since OpenBSD 2.6. an icon that's been serving since forever ⭐

and before OpenSSL 0.9.8, neither pkey nor cert were allowed to be NULL, and a value of -1 was not allowed for nid_key, nid_cert, and mac_iter. so like... glow-up era, we love to see it πŸ“ˆ


ngl bestie, if you're relying on the old behaviour from before OpenSSL 0.9.8, that's a vintage situation and you should probably look at it 😭

and that's the whole page, bestie! brought to you by Debian, dated June 8, 2025 β€” love that for us πŸ’– mwah, go forth and PKCS12_create() responsibly πŸŽ€βœ¨

πŸ“¦ where this page comes from