PEM_BYTES_READ_BIO(3)
π PEM_BYTES_READ_BIO(3) π
okay so this is the PEM_BYTES_READ_BIO(3) page from the Library Functions Manual, and itβs a libcrypto moment, bestie. Weβre reading a PEM-encoded data structure from a BIO, and honestly? iconic behavior. letβs get into it π¦
πΈ NAME πΈ
PEM_bytes_read_bio β read a PEM-encoded data structure from a BIO.
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/pem.h>
int
PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
const char *name, BIO *in_bp, pem_password_cb *cb, void *u);
π DESCRIPTION π
okay so PEM_bytes_read_bio() reads and PEM decodes the first object of type name (like RSA PRIVATE KEY, CERTIFICATE, etc.) from in_bp. If multiple PEM-encoded data structures are present in the same stream, it skips non-matching data types and continues reading. Before reading each PEM object, lines not starting with "-----BEGIN " are also skipped; see PEM_read_bio(3) for details of PEM parsing. sheβs persistent, sheβs picky, she knows what she wants πββοΈ
The PEM header may indicate that the following data is encrypted; if so, the data is decrypted, optionally using cb and u, as described in pem_password_cb(3).
Some data types have compatibility aliases, such as a file containing X509 CERTIFICATE matching a request for the deprecated type CERTIFICATE. The actual type indicated by the file is returned in *pnm if pnm is non-NULL. The caller must free the storage pointed to by *pnm. yes bestie, that memory is yours to clean up π§Ή
The returned data is the DER-encoded form of the requested type, in *pdata with length *plen. The caller must free the storage pointed to by *pdata. another free-your-own-storage situation, no cap π
π₯ RETURN VALUES π₯
PEM_bytes_read_bio() returns 1 for success or 0 for failure. thatβs it, thatβs the vibe check: slay or no-slay β¨
π ERRORS π
Diagnostics that can be retrieved with ERR_get_error(3), ERR_GET_REASON(3), and ERR_reason_error_string(3) include:
PEM_R_NO_START_LINEβ"no start line": no more PEM objects were found in the input. This can happen when the input contains no PEM objects at all, or only objects that do not match the typename.PEM_R_NOT_PROC_TYPEβ"not proc type": the first PEM header does not start with"Proc-Type: ".PEM_R_NOT_ENCRYPTEDβ"not encrypted": theProc-Typeheader differs from"4,ENCRYPTED".PEM_R_SHORT_HEADERβ"short header": theProc-Typeheader is the last header line.PEM_R_NOT_DEK_INFOβ"not dek info": the second PEM header does not start with"DEK-Info: ".PEM_R_UNSUPPORTED_ENCRYPTIONβ"unsupported encryption": the cipher name given in theDEK-Infoheader is unknown toEVP_get_cipherbyname(3).PEM_R_BAD_IV_CHARSβ"bad iv chars": the word following the cipher name in theDEK-Infoheader contains bytes that are not hexadecimal digits. This also happens when the initialization vector is missing or too short.PEM_R_BAD_PASSWORD_READβ"bad password read":cbreported failure. This may for example happen when the user mistypes the password. weβve all been there πPEM_R_BAD_DECRYPTβ"bad decrypt":EVP_DecryptInit_ex(3),EVP_DecryptUpdate(3), orEVP_DecryptFinal_ex(3)failed.
Additional types of errors can result from PEM_read_bio(3).
π«Ά SEE ALSO π«Ά
π STANDARDS π
RFC 1421: Privacy Enhancement for Internet Electronic Mail (PEM), Part I
π HISTORY π
PEM_bytes_read_bio() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2. sheβs been around, and sheβs still serving π
π thatβs the whole page, bestie! footer tea: source/versionDebian, dateJuly 16, 2025. byeee, go read some PEM! π
π¦ 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) 2020 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2017 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms