D2I_PKCS8PRIVATEKEY_BIO(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

✨ NAME ✨

okay so bestie, welcome to the OpenSSL manual page D2I_PKCS8PRIVATEKEY_BIO(3ossl) β€” it’s giving PKCS#8 format private key functions and it’s lowkey iconic. πŸ’…

The whole squad is:

  • d2i_PKCS8PrivateKey_bio
  • d2i_PKCS8PrivateKey_fp
  • i2d_PKCS8PrivateKey_bio
  • i2d_PKCS8PrivateKey_fp
  • i2d_PKCS8PrivateKey_nid_bio
  • i2d_PKCS8PrivateKey_nid_fp

No cap, that’s the lineup. 🫢


πŸ› οΈ SYNOPSIS πŸ› οΈ

First things first, include the header:

#include <openssl/pem.h>

Then the function signatures, exactly as they are:

EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);

int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
                            char *kstr, int klen,
                            pem_password_cb *cb, void *u);

int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
                           char *kstr, int klen,
                           pem_password_cb *cb, void *u);

int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
                                char *kstr, int klen,
                                pem_password_cb *cb, void *u);

int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
                               char *kstr, int klen,
                               pem_password_cb *cb, void *u);

🌸 DESCRIPTION 🌸

The PKCS#8 functions encode and decode private keys in PKCS#8 format, using both PKCS#5 v1.5 and PKCS#5 v2.0 password based encryption algorithms. Periodt. πŸ”₯

Other than the use of DER as opposed to PEM, these functions are identical to the corresponding PEM function as described in PEM_read_PrivateKey(3). So yeah, same vibe, different encoding era. πŸ’…


πŸ“ NOTES πŸ“

  • These functions are currently the only way to store encrypted private keys using DER format. That’s the whole assignment, bestie. πŸ‘‘
  • Currently all the functions use BIOs or FILE pointers, and there are no functions which work directly on memory. This can be readily worked around by converting the buffers to memory BIOs β€” see BIO_s_mem(3) for details. iykyk. 🧚
  • These functions make no assumption regarding the pass phrase received from the password callback. It will simply be treated as a byte sequence. No extra reading into it, no judging your choices, just bytes. 🫢

πŸŽ€ RETURN VALUES πŸŽ€

  • d2i_PKCS8PrivateKey_bio() and d2i_PKCS8PrivateKey_fp() return a valid EVP_PKEY structure or NULL if an error occurred. So if you get NULL, that’s your error era. 😭
  • i2d_PKCS8PrivateKey_bio(), i2d_PKCS8PrivateKey_fp(), i2d_PKCS8PrivateKey_nid_bio() and i2d_PKCS8PrivateKey_nid_fp() return 1 on success or 0 on error. Very binary of them, and honestly? Slay. πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

Go read those too, bestie β€” the lore is interconnected. πŸ¦‹


Copyright 2002-2018 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>.


πŸ’– Source vibe check: OpenSSL 3.5.6, dated 2026-04-07, manual D2I_PKCS8PRIVATEKEY_BIO(3ossl). Bye bestie, go encrypt responsibly! 🫢✨

πŸ“¦ where this page comes from