---
name: "PEM_read_bio_ex"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/PEM_read_bio_ex"
---

# PEM\_read\_bio\_ex(3ssl)

read PEM format files with custom processing

## NAME

PEM\_read\_bio\_ex, PEM\_FLAG\_SECURE, PEM\_FLAG\_EAY\_COMPATIBLE, PEM\_FLAG\_ONLY\_B64 - read PEM format files with custom processing

## SYNOPSIS

```
 #include <openssl/pem.h>
 #define PEM_FLAG_SECURE             0x1
 #define PEM_FLAG_EAY_COMPATIBLE     0x2
 #define PEM_FLAG_ONLY_B64           0x4
 int PEM_read_bio_ex(BIO *in, char **name, char **header,
                     unsigned char **data, long *len, unsigned int flags);
```

## DESCRIPTION

**PEM\_read\_bio\_ex()** reads in PEM formatted data from an input BIO, outputting the name of the type of contained data, the header information regarding the possibly encrypted data, and the binary data payload (after base64 decoding). It should generally only be used to implement PEM\_read\_bio\_-family functions for specific data types or other usage, but is exposed to allow greater flexibility over how processing is performed, if needed.

If PEM\_FLAG\_SECURE is set, the intermediate buffers used to read in lines of input are allocated from the secure heap.

If PEM\_FLAG\_EAY\_COMPATIBLE is set, a simple algorithm is used to remove whitespace and control characters from the end of each line, so as to be compatible with the historical behavior of **PEM\_read\_bio()**.

If PEM\_FLAG\_ONLY\_B64 is set, all characters are required to be valid base64 characters (or newlines); non-base64 characters are treated as end of input.

If neither PEM\_FLAG\_EAY\_COMPATIBLE or PEM\_FLAG\_ONLY\_B64 is set, control characters are ignored.

If both PEM\_FLAG\_EAY\_COMPATIBLE and PEM\_FLAG\_ONLY\_B64 are set, an error is returned; these options are not compatible with each other.

## NOTES

The caller must release the storage allocated for \*name, \*header, and \*data. If PEM\_FLAG\_SECURE was set, use **OPENSSL\_secure\_free()**; otherwise, **OPENSSL\_free()** is used.

## RETURN VALUES

**PEM\_read\_bio\_ex()** returns 1 for success or 0 for failure.

## SEE ALSO

**PEM\_bytes\_read\_bio**(3)

## HISTORY

The **PEM\_read\_bio\_ex()** function was added in OpenSSL 1.1.1.

## COPYRIGHT

Copyright 2017 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\>.
