D2I_PKCS12(3)
π D2I_PKCS12(3) β the libcrypto glow-up
okay so bestie, welcome to the D2I_PKCS12(3) page, straight out of the Library Functions Manual, and no, that title is not a typo, it's just how the C kids name things π
β¨ NAME β¨
d2i_PKCS12, i2d_PKCS12, d2i_PKCS12_bio, i2d_PKCS12_bio, d2i_PKCS12_fp, i2d_PKCS12_fp, d2i_PKCS12_MAC_DATA, i2d_PKCS12_MAC_DATA, d2i_PKCS12_SAFEBAG, i2d_PKCS12_SAFEBAG, d2i_PKCS12_BAGS, i2d_PKCS12_BAGS β decode and encode PKCS#12 structures π¦
(like, yes, that's twelve functions and no, I'm not going to pretend that's a normal amount of functions. it's giving "one family, twelve siblings, all iconic.")
πΈ SYNOPSIS πΈ
first up: library βlibcryptoβ and #include <openssl/pkcs12.h> β the lil duo that makes all of this work π
PKCS12 *
d2i_PKCS12(PKCS12 **val_out, const unsigned char **der_in, long length);
int
i2d_PKCS12(PKCS12 *val_in, unsigned char **der_out);
PKCS12 *
d2i_PKCS12_bio(BIO *in_bio, PKCS12 **val_out);
int
i2d_PKCS12_bio(BIO *out_bio, PKCS12 *val_in);
PKCS12 *
d2i_PKCS12_fp(FILE *in_fp, PKCS12 **val_out);
int
i2d_PKCS12_fp(FILE *out_fp, PKCS12 *val_in);
PKCS12_MAC_DATA *
d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **val_out,
const unsigned char **der_in, long length);
int
i2d_PKCS12_MAC_DATA(PKCS12_MAC_DATA *val_in, unsigned char **der_out);
PKCS12_SAFEBAG *
d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **val_out,
const unsigned char **der_in, long length);
int
i2d_PKCS12_SAFEBAG(PKCS12_SAFEBAG *val_in, unsigned char **der_out);
PKCS12_BAGS *
d2i_PKCS12_BAGS(PKCS12_BAGS **val_out, const unsigned char **der_in,
long length);
int
i2d_PKCS12_BAGS(PKCS12_BAGS *val_in, unsigned char **der_out);
look at all those signatures. main character energy fr fr π
π DESCRIPTION π
okay so the big picture: these functions decode and encode PKCS#12 structures. for the juicy details on semantics, examples, caveats, and bugs, go read ASN1_item_d2i(3) β that's the parent page, the lore, the iykyk π«Ά
d2i_PKCS12()andi2d_PKCS12()β decode and encode an ASN.1 PFX (personal information exchange) structure, defined in RFC 7292 section 4. yes, "personal information exchange" β it's literally in the name, it's a whole vibe πd2i_PKCS12_bio(),i2d_PKCS12_bio(),d2i_PKCS12_fp(), andi2d_PKCS12_fp()β same deal, except they decode or encode using aBIOor aFILEpointer. same energy, different plumbing π§d2i_PKCS12_MAC_DATA()andi2d_PKCS12_MAC_DATA()β decode and encode an ASN.1 MacData structure, defined in RFC 7292 section 4 πd2i_PKCS12_SAFEBAG()andi2d_PKCS12_SAFEBAG()β decode and encode an ASN.1 SafeBag structure, defined in RFC 7292 section 4.2 πd2i_PKCS12_BAGS()andi2d_PKCS12_BAGS()β decode and encode the bagValue field of an ASN.1 SafeBag structure β
(the naming convention is d2i = "DER to internal" and i2d = "internal to DER", so yeah, you already knew that, you're so smart π)
π₯ RETURN VALUES π₯
pay attention bestie, because the returns are not all the same and that's exactly the kind of thing that bites you at 2am π
d2i_PKCS12(),d2i_PKCS12_bio(), andd2i_PKCS12_fp()β return aPKCS12object, orNULLif an error occurs πd2i_PKCS12_MAC_DATA(),d2i_PKCS12_SAFEBAG(), andd2i_PKCS12_BAGS()β return aPKCS12_MAC_DATA,PKCS12_SAFEBAG, orPKCS12_BAGSobject, respectively, orNULLif an error occurs πi2d_PKCS12(),i2d_PKCS12_MAC_DATA(),i2d_PKCS12_SAFEBAG(), andi2d_PKCS12_BAGS()β return the number of bytes successfully encoded, or a negative value if an error occurs. yes, negative. not zero. don't check== 0, check< 0, I'm begging π«i2d_PKCS12_bio()andi2d_PKCS12_fp()β return1for success or0if an error occurs. classic. iconic. extremely int-coded β¨
ngl the mix of "returnsNULL", "returns negative", and "returns1or0" is a vibe check you have to pass every single time. no cap. π¨
π¦ SEE ALSO π¦
go read these next, they're literally the friends of this page:
π STANDARDS π
RFC 7292: PKCS #12: Personal Information Exchange Syntax β that's the whole standard, that's the source material, that's the blueprint π
π HISTORY π
d2i_PKCS12(), i2d_PKCS12(), d2i_PKCS12_bio(), i2d_PKCS12_bio(), d2i_PKCS12_fp(), i2d_PKCS12_fp(), d2i_PKCS12_MAC_DATA(), i2d_PKCS12_MAC_DATA(), d2i_PKCS12_SAFEBAG(), i2d_PKCS12_SAFEBAG(), d2i_PKCS12_BAGS(), and i2d_PKCS12_BAGS() first appeared in OpenSSL 0.9.3 and have been available since OpenBSD 2.6 π§ββοΈ
(so they've been doing this since before most of us could read. legends only. π)
and that's the page! sourced from the Debian build, dated June 8, 2025, landing in your group chat like a little gift π slay, bye, go encode something 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) 2016 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms