1BIO_F_BASE64(3ossl)                 OpenSSL                BIO_F_BASE64(3ossl)
2
3
4

NAME

6       BIO_f_base64 - base64 BIO filter
7

SYNOPSIS

9        #include <openssl/bio.h>
10        #include <openssl/evp.h>
11
12        const BIO_METHOD *BIO_f_base64(void);
13

DESCRIPTION

15       BIO_f_base64() returns the base64 BIO method. This is a filter BIO that
16       base64 encodes any data written through it and decodes any data read
17       through it.
18
19       Base64 BIOs do not support BIO_gets() or BIO_puts().
20
21       For writing, output is by default divided to lines of length 64
22       characters and there is always a newline at the end of output.
23
24       For reading, first line should be at most 1024 characters long. If it
25       is longer then it is ignored completely.  Other input lines can be of
26       any length. There must be a newline at the end of input.
27
28       This behavior can be changed with BIO_FLAGS_BASE64_NO_NL flag.
29
30       BIO_flush() on a base64 BIO that is being written through is used to
31       signal that no more data is to be encoded: this is used to flush the
32       final block through the BIO.
33
34       The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags().  For
35       writing, it causes all data to be written on one line without newline
36       at the end.  For reading, it expects the data to be all on one line
37       (with or without a trailing newline).
38

NOTES

40       Because of the format of base64 encoding the end of the encoded block
41       cannot always be reliably determined.
42

RETURN VALUES

44       BIO_f_base64() returns the base64 BIO method.
45

EXAMPLES

47       Base64 encode the string "Hello World\n" and write the result to
48       standard output:
49
50        BIO *bio, *b64;
51        char message[] = "Hello World \n";
52
53        b64 = BIO_new(BIO_f_base64());
54        bio = BIO_new_fp(stdout, BIO_NOCLOSE);
55        BIO_push(b64, bio);
56        BIO_write(b64, message, strlen(message));
57        BIO_flush(b64);
58
59        BIO_free_all(b64);
60
61       Read Base64 encoded data from standard input and write the decoded data
62       to standard output:
63
64        BIO *bio, *b64, *bio_out;
65        char inbuf[512];
66        int inlen;
67
68        b64 = BIO_new(BIO_f_base64());
69        bio = BIO_new_fp(stdin, BIO_NOCLOSE);
70        bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
71        BIO_push(b64, bio);
72        while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
73            BIO_write(bio_out, inbuf, inlen);
74
75        BIO_flush(bio_out);
76        BIO_free_all(b64);
77

BUGS

79       The ambiguity of EOF in base64 encoded data can cause additional data
80       following the base64 encoded block to be misinterpreted.
81
82       There should be some way of specifying a test that the BIO can perform
83       to reliably determine EOF (for example a MIME boundary).
84
86       Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
87
88       Licensed under the Apache License 2.0 (the "License").  You may not use
89       this file except in compliance with the License.  You can obtain a copy
90       in the file LICENSE in the source distribution or at
91       <https://www.openssl.org/source/license.html>.
92
93
94
953.0.5                             2022-11-01               BIO_F_BASE64(3ossl)
Impressum