D2I_PKCS8_PRIV_KEY_INFO(3)
β¨ 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(), andd2i_PKCS8_PRIV_KEY_INFO_fp()return aPKCS8_PRIV_KEY_INFOobject orNULLif 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()andi2d_PKCS8_PRIV_KEY_INFO_fp()return1for success or0if 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
- 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