PKCS12_CREATE(3)
π 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β thefriendlyNameto 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 beNULLto indicate that no key or certificate is required. no key? no cert? no problem, it's valid π
π encryption params π
nid_keyandnid_certare the encryption algorithms that should be used for the key and the certificate, respectively.- if either
nid_keyornid_certis set to-1, no encryption will be used. (ngl, that's the bold choice π)
π§ iteration counts π§
iteris the encryption algorithm iteration count to use.mac_iteris the MAC iteration count to use.- if
mac_iteris set to-1, the MAC will be omitted entirely. periodt.
π₯ keytype π₯
keytypeis 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(currently2048) - 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
NULLif an error occurred π
literally that simple. check your returns, bestie, always π«Ά
π SEE ALSO π
crypto(3)d2i_PKCS12(3)PKCS12_new(3)PKCS12_newpass(3)PKCS12_parse(3)PKCS12_SAFEBAG_new(3)X509_keyid_set1(3)
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
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2002, 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms