D2I_PKCS8_PRIV_KEY_INFO(3)

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

✨ D2I_PKCS8_PRIV_KEY_INFO(3) ✨

okay bestie, welcome to the D2I_PKCS8_PRIV_KEY_INFO(3) page β€” yes, that whole mouthful β€” from the Library Functions Manual. It’s giving β€œprivate key decode/encode squad,” and honestly? iconic.


✨ NAME ✨

d2i_PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_bio, i2d_PKCS8_PRIV_KEY_INFO_bio, d2i_PKCS8_PRIV_KEY_INFO_fp, i2d_PKCS8_PRIV_KEY_INFO_fp β€” decode and encode PKCS#8 private key


πŸŽ€ SYNOPSIS πŸŽ€

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

PKCS8_PRIV_KEY_INFO *
d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **val_out,
    const unsigned char **der_in, long length);

int
i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *val_in,
    unsigned char **der_out);

PKCS8_PRIV_KEY_INFO *
d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *in_bio, PKCS8_PRIV_KEY_INFO **val_out);

int
i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *out_bio, PKCS8_PRIV_KEY_INFO *val_in);

PKCS8_PRIV_KEY_INFO *
d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *in_fp, PKCS8_PRIV_KEY_INFO **val_out);

int
i2d_PKCS8_PRIV_KEY_INFO_fp(BIO *out_fp, PKCS8_PRIV_KEY_INFO *val_in);

πŸ’… DESCRIPTION πŸ’…

So d2i_PKCS8_PRIV_KEY_INFO() and i2d_PKCS8_PRIV_KEY_INFO() are the main duo: they decode and encode an ASN.1 PrivateKeyInfo structure, and that structure is defined in RFC 5208 section 5. periodt.

d2i_PKCS8_PRIV_KEY_INFO_bio(), i2d_PKCS8_PRIV_KEY_INFO_bio(), d2i_PKCS8_PRIV_KEY_INFO_fp(), and i2d_PKCS8_PRIV_KEY_INFO_fp() are literally the same vibe, except they decode or encode using a BIO or FILE pointer.

For the full tea on semantics, examples, caveats, and bugs, go read ASN1_item_d2i(3) β€” iykyk.

These functions all use unencrypted DER format. If you wanna store private keys in encrypted form, consider d2i_PKCS8PrivateKey_bio(3) or PEM_write_PKCS8PrivateKey(3).

🚨 heads up, bestie: the key word is unencrypted. These are all unencrypted DER format. If encrypted storage is the goal, the encrypted-form options above are the ones to check.

🌸 RETURN VALUES 🌸

  • d2i_PKCS8_PRIV_KEY_INFO(), d2i_PKCS8_PRIV_KEY_INFO_bio(), and d2i_PKCS8_PRIV_KEY_INFO_fp() return a PKCS8_PRIV_KEY_INFO object or NULL if an error occurs.
  • i2d_PKCS8_PRIV_KEY_INFO() returns the number of bytes successfully encoded or a negative value if an error occurs.
  • i2d_PKCS8_PRIV_KEY_INFO_bio() and i2d_PKCS8_PRIV_KEY_INFO_fp() return 1 for success or 0 if an error occurs.

πŸ¦‹ SEE ALSO πŸ¦‹

ASN1_item_d2i(3), d2i_PKCS8PrivateKey_bio(3), d2i_PrivateKey(3), PEM_write_PKCS8_PRIV_KEY_INFO(3), PKCS8_PRIV_KEY_INFO_new(3)


⭐ STANDARDS ⭐

RFC 5208: PKCS#8: Private-Key Information Syntax Specification


πŸ‘‘ HISTORY πŸ‘‘

d2i_PKCS8_PRIV_KEY_INFO() and i2d_PKCS8_PRIV_KEY_INFO() first appeared in OpenSSL 0.9.3.

d2i_PKCS8_PRIV_KEY_INFO_bio(), i2d_PKCS8_PRIV_KEY_INFO_bio(), d2i_PKCS8_PRIV_KEY_INFO_fp(), and i2d_PKCS8_PRIV_KEY_INFO_fp() first appeared in OpenSSL 0.9.4.

All these functions have been available since OpenBSD 2.6.


πŸ’– okay that’s the whole page, bestie β€” source/version: Debian, date: June 8, 2025. Go forth and decode/encode responsibly πŸ’–

πŸ“¦ where this page comes from