5 BIO_f_base64 - base64 BIO filter
9 =for openssl multiple includes
11 #include <openssl/bio.h>
12 #include <openssl/evp.h>
14 const BIO_METHOD *BIO_f_base64(void);
18 BIO_f_base64() returns the base64 BIO method. This is a filter
19 BIO that base64 encodes any data written through it and decodes
20 any data read through it.
22 Base64 BIOs do not support BIO_gets() or BIO_puts().
24 For writing, output is by default divided to lines of length 64
25 characters and there is always a newline at the end of output.
27 For reading, first line should be at most 1024
28 characters long. If it is longer then it is ignored completely.
29 Other input lines can be of any length. There must be a newline
32 This behavior can be changed with BIO_FLAGS_BASE64_NO_NL flag.
34 BIO_flush() on a base64 BIO that is being written through is
35 used to signal that no more data is to be encoded: this is used
36 to flush the final block through the BIO.
38 The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags().
39 For writing, it causes all data to be written on one line without
41 For reading, it expects the data to be all on one line (with or
42 without a trailing newline).
46 Because of the format of base64 encoding the end of the encoded
47 block cannot always be reliably determined.
51 BIO_f_base64() returns the base64 BIO method.
55 Base64 encode the string "Hello World\n" and write the result
59 char message[] = "Hello World \n";
61 b64 = BIO_new(BIO_f_base64());
62 bio = BIO_new_fp(stdout, BIO_NOCLOSE);
64 BIO_write(b64, message, strlen(message));
69 Read Base64 encoded data from standard input and write the decoded
70 data to standard output:
72 BIO *bio, *b64, *bio_out;
76 b64 = BIO_new(BIO_f_base64());
77 bio = BIO_new_fp(stdin, BIO_NOCLOSE);
78 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
80 while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
81 BIO_write(bio_out, inbuf, inlen);
88 The ambiguity of EOF in base64 encoded data can cause additional
89 data following the base64 encoded block to be misinterpreted.
91 There should be some way of specifying a test that the BIO can perform
92 to reliably determine EOF (for example a MIME boundary).
96 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
98 Licensed under the Apache License 2.0 (the "License"). You may not use
99 this file except in compliance with the License. You can obtain a copy
100 in the file LICENSE in the source distribution or at
101 L<https://www.openssl.org/source/license.html>.