| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "BIO_F_BASE64 3SSL" |
| 58 |
.TH BIO_F_BASE64 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
BIO_f_base64 \- base64 BIO filter |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 2 |
| 68 |
\& #include <openssl/bio.h> |
| 69 |
\& #include <openssl/evp.h> |
| 70 |
\& |
| 71 |
\& const BIO_METHOD *BIO_f_base64(void); |
| 72 |
.Ve |
| 73 |
.SH DESCRIPTION |
| 74 |
.IX Header "DESCRIPTION" |
| 75 |
\&\fBBIO_f_base64()\fR returns the base64 BIO method. This is a filter |
| 76 |
BIO that base64 encodes any data written through it and decodes |
| 77 |
any data read through it. |
| 78 |
.PP |
| 79 |
Base64 BIOs do not support \fBBIO_gets()\fR or \fBBIO_puts()\fR. |
| 80 |
.PP |
| 81 |
For writing, by default output is divided to lines of length 64 |
| 82 |
characters and there is a newline at the end of output. |
| 83 |
This behavior can be changed with \fBBIO_FLAGS_BASE64_NO_NL\fR flag. |
| 84 |
.PP |
| 85 |
For reading, the first line of base64 content should be at most 1024 bytes long |
| 86 |
including newline unless the flag \fBBIO_FLAGS_BASE64_NO_NL\fR is set. |
| 87 |
Subsequent input lines can be of any length (i.e., newlines may appear anywhere |
| 88 |
in the input) and a newline at the end of input is not needed. |
| 89 |
.PP |
| 90 |
Also when reading, unless the flag \fBBIO_FLAGS_BASE64_NO_NL\fR is set, initial |
| 91 |
lines that contain non\-base64 content (whitespace is tolerated and ignored) are |
| 92 |
skipped, as are lines longer than 1024 bytes. |
| 93 |
Decoding starts with the first line that is shorter than 1024 bytes (including |
| 94 |
the newline) and consists of only (at least one) valid base64 characters plus |
| 95 |
optional whitespace. |
| 96 |
Decoding stops when base64 padding is encountered, a soft end-of-input |
| 97 |
character (\fB\-\fR, see \fBEVP_DecodeUpdate\fR\|(3)) occurs as the first byte after a |
| 98 |
complete group of 4 valid base64 characters is decoded, or when an error occurs |
| 99 |
(e.g. due to input characters other than valid base64 or whitespace). |
| 100 |
.PP |
| 101 |
If decoding stops as a result of an error, the first \fBBIO_read\fR\|(3) that |
| 102 |
returns no decoded data will typically return a negative result, rather |
| 103 |
than 0 (which indicates normal end of input). |
| 104 |
However, a negative return value can also occur if the underlying BIO |
| 105 |
supports retries, see \fBBIO_should_read\fR\|(3) and \fBBIO_set_mem_eof_return\fR\|(3). |
| 106 |
.PP |
| 107 |
\&\fBBIO_flush()\fR on a base64 BIO that is being written through is |
| 108 |
used to signal that no more data is to be encoded: this is used |
| 109 |
to flush the final block through the BIO. |
| 110 |
.PP |
| 111 |
The flag \fBBIO_FLAGS_BASE64_NO_NL\fR can be set with \fBBIO_set_flags()\fR. |
| 112 |
For writing, it causes all data to be written on one line without |
| 113 |
newline at the end. |
| 114 |
For reading, it removes all expectations on newlines in the input data. |
| 115 |
.SH NOTES |
| 116 |
.IX Header "NOTES" |
| 117 |
Because of the format of base64 encoding the end of the encoded |
| 118 |
block cannot always be reliably determined. |
| 119 |
.SH "RETURN VALUES" |
| 120 |
.IX Header "RETURN VALUES" |
| 121 |
\&\fBBIO_f_base64()\fR returns the base64 BIO method. |
| 122 |
.SH EXAMPLES |
| 123 |
.IX Header "EXAMPLES" |
| 124 |
Base64 encode the string "Hello World\en" and write the result |
| 125 |
to standard output: |
| 126 |
.PP |
| 127 |
.Vb 2 |
| 128 |
\& BIO *bio, *b64; |
| 129 |
\& char message[] = "Hello World \en"; |
| 130 |
\& |
| 131 |
\& b64 = BIO_new(BIO_f_base64()); |
| 132 |
\& bio = BIO_new_fp(stdout, BIO_NOCLOSE); |
| 133 |
\& BIO_push(b64, bio); |
| 134 |
\& BIO_write(b64, message, strlen(message)); |
| 135 |
\& BIO_flush(b64); |
| 136 |
\& |
| 137 |
\& BIO_free_all(b64); |
| 138 |
.Ve |
| 139 |
.PP |
| 140 |
Read base64 encoded data from standard input and write the decoded |
| 141 |
data to standard output: |
| 142 |
.PP |
| 143 |
.Vb 3 |
| 144 |
\& BIO *bio, *b64, *bio_out; |
| 145 |
\& char inbuf[512]; |
| 146 |
\& int inlen; |
| 147 |
\& |
| 148 |
\& b64 = BIO_new(BIO_f_base64()); |
| 149 |
\& bio = BIO_new_fp(stdin, BIO_NOCLOSE); |
| 150 |
\& bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); |
| 151 |
\& BIO_push(b64, bio); |
| 152 |
\& while ((inlen = BIO_read(b64, inbuf, 512)) > 0) |
| 153 |
\& BIO_write(bio_out, inbuf, inlen); |
| 154 |
\& |
| 155 |
\& BIO_flush(bio_out); |
| 156 |
\& BIO_free_all(b64); |
| 157 |
.Ve |
| 158 |
.SH BUGS |
| 159 |
.IX Header "BUGS" |
| 160 |
The hyphen character (\fB\-\fR) is treated as an ad hoc soft end-of-input |
| 161 |
character when it occurs at the start of a base64 group of 4 encoded |
| 162 |
characters. |
| 163 |
.PP |
| 164 |
This heuristic works to detect the ends of base64 blocks in PEM or |
| 165 |
multi-part MIME, provided there are no stray hyphens in the middle |
| 166 |
input. |
| 167 |
But it is just a heuristic, and sufficiently unusual input could produce |
| 168 |
unexpected results. |
| 169 |
.PP |
| 170 |
There should perhaps be some way of specifying a test that the BIO can perform |
| 171 |
to reliably determine EOF (for example a MIME boundary). |
| 172 |
.PP |
| 173 |
It may be possible for \fBBIO_read\fR\|(3) to return zero, rather than \-1, even if |
| 174 |
an error has been detected, more tests are needed to cover all the potential |
| 175 |
error paths. |
| 176 |
.SH "SEE ALSO" |
| 177 |
.IX Header "SEE ALSO" |
| 178 |
\&\fBBIO_read\fR\|(3), |
| 179 |
\&\fBBIO_should_read\fR\|(3), |
| 180 |
\&\fBBIO_set_mem_eof_return\fR\|(3), |
| 181 |
\&\fBEVP_DecodeUpdate\fR\|(3). |
| 182 |
.SH COPYRIGHT |
| 183 |
.IX Header "COPYRIGHT" |
| 184 |
Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved. |
| 185 |
.PP |
| 186 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 187 |
this file except in compliance with the License. You can obtain a copy |
| 188 |
in the file LICENSE in the source distribution or at |
| 189 |
<https://www.openssl.org/source/license.html>. |