PKCS12_SAFEBAG_CREATE_CERT(3ossl)
π PKCS12_SAFEBAG_CREATE_CERT β the OpenSSL girlies' guide to safeBags π
okay so bestie, this one lives in the OpenSSL 3ossl manual, section 3, and it's literally all about creating PKCS#12 safeBag objects. If you've ever been like "hmm what even is a safeBag" β it's a lil container that holds one (1) piece of stuff inside a PKCS#12 file, and this page is the seven functions that make them. Let's go π
β¨ NAME β¨
PKCS12_SAFEBAG_create_cert, PKCS12_SAFEBAG_create_crl, PKCS12_SAFEBAG_create_secret, PKCS12_SAFEBAG_create0_p8inf, PKCS12_SAFEBAG_create0_pkcs8, PKCS12_SAFEBAG_create_pkcs8_encrypt, PKCS12_SAFEBAG_create_pkcs8_encrypt_ex β they create PKCS#12 safeBag objects. that's the whole job. slay π
πΈ SYNOPSIS πΈ
#include <openssl/pkcs12.h>
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_secret(int type, int vtype,
const unsigned char* value,
int len);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
const char *pass,
int passlen,
unsigned char *salt,
int saltlen, int iter,
PKCS8_PRIV_KEY_INFO *p8inf);
PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt_ex(int pbe_nid,
const char *pass,
int passlen,
unsigned char *salt,
int saltlen, int iter,
PKCS8_PRIV_KEY_INFO *p8inf,
OSSL_LIB_CTX *ctx,
const char *propq);
π¦ DESCRIPTION π¦
bestie, it's one function per bag type. here's the lineup π
PKCS12_SAFEBAG_create_cert()β makes a brand newPKCS12_SAFEBAGof typeNID_certBag, and it's holding the certificate you hand it. certificate bag, certified cute πPKCS12_SAFEBAG_create_crl()β same energy, but it's aNID_crlBagand it's holding thecrlyou passed in. revocation never looked so good πPKCS12_SAFEBAG_create_secret()β makes a newPKCS12_SAFEBAGof the type that corresponds to a PKCS#12secretBag. The secretBag's contents get tagged astype, with an ASN1 value of typevtypebuilt out of the bytes invalue, which islenlong. it's giving "custom content, my rules" β¨PKCS12_SAFEBAG_create0_p8inf()β makes a newPKCS12_SAFEBAGof typeNID_keyBagholding thePKCS8structure you gave it. the "0" in the name is not a typo, it's just how she's spelled, periodt.PKCS12_SAFEBAG_create0_pkcs8()β makes a newPKCS12_SAFEBAGof typeNID_pkcs8ShroudedKeyBagholding thePKCS8structure you gave it. shrouded = wrapped up, mysterious, main character energy π§PKCS12_SAFEBAG_create_pkcs8_encrypt()β makes a newPKCS12_SAFEBAGof typeNID_pkcs8ShroudedKeyBagby encrypting thePKCS8you passed asp8inf. deets:- if
pbe_nidis0, a default encryption algorithm gets used (you don't have to pick one, she's got you π«Ά) passis the passphraseiteris the iteration count β and ifiteris zero, a default value of2048is used- if
saltisNULL, a salt gets generated randomly. we love a spontaneous queen π²
- if
PKCS12_SAFEBAG_create_pkcs8_encrypt_ex()β literally identical toPKCS12_SAFEBAG_create_pkcs8_encrypt(), except it also lets you pass a library contextctxand a property querypropqso you can select which algorithm implementations get used. same girl, upgraded fit π
π NOTES π
PKCS12_SAFEBAG_create_pkcs8_encrypt()makes assumptions about how the given pass phrase is encoded. go readpassphrase-encoding(7)for the tea, bestie. fr fr.
also β PKCS12_SAFEBAG_create_secret() was added in OpenSSL 3.0. she's the new girl but she belongs here π
π RETURN VALUES π
All of these functions return a valid PKCS12_SAFEBAG structure... or NULL if an error happened π. that's it. valid bag or nothing.
β CONFORMING TO β
IETF RFC 7292 (<https://tools.ietf.org/html/rfc7292>) β the standards girlies said what they said and we're following it πΈ
π SEE ALSO π
PKCS12_create(3), PKCS12_add_safe(3), PKCS12_add_safes(3)
iykyk β go read those next if you want the whole saga π
π HISTORY π
PKCS12_SAFEBAG_create_pkcs8_encrypt_ex() was added in OpenSSL 3.0. the _ex variant is the newer, glowier version of her sister β¨
π COPYRIGHT π
Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page, no cap π«Ά this was OpenSSL 3.5.9, dated 2026-09-29, and it's the PKCS12_SAFEBAG_CREATE_CERT(3ossl) page β love that for us, go make some safeBags bestie πβ¨π
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms