5 BIO_f_base64 - base64 BIO filter
9 #include <openssl/bio.h>
10 #include <openssl/evp.h>
12 BIO_METHOD * BIO_f_base64(void);
16 BIO_f_base64() returns the base64 BIO method. This is a filter
17 BIO that base64 encodes any data written through it and decodes
18 any data read through it.
20 Base64 BIOs do not support BIO_gets() or BIO_puts().
22 BIO_flush() on a base64 BIO that is being written through is
23 used to signal that no more data is to be encoded: this is used
24 to flush the final block through the BIO.
26 The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags()
27 to encode the data all on one line or expect the data to be all
32 Because of the format of base64 encoding the end of the encoded
33 block cannot always be reliably determined.
37 BIO_f_base64() returns the base64 BIO method.
41 Base64 encode the string "Hello World\n" and write the result
45 char message[] = "Hello World \n";
47 b64 = BIO_new(BIO_f_base64());
48 bio = BIO_new_fp(stdout, BIO_NOCLOSE);
49 bio = BIO_push(b64, bio);
50 BIO_write(bio, message, strlen(message));
55 Read Base64 encoded data from standard input and write the decoded
56 data to standard output:
58 BIO *bio, *b64, *bio_out;
62 b64 = BIO_new(BIO_f_base64());
63 bio = BIO_new_fp(stdin, BIO_NOCLOSE);
64 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
65 bio = BIO_push(b64, bio);
66 while((inlen = BIO_read(bio, inbuf, 512)) > 0)
67 BIO_write(bio_out, inbuf, inlen);
73 The ambiguity of EOF in base64 encoded data can cause additional
74 data following the base64 encoded block to be misinterpreted.
76 There should be some way of specifying a test that the BIO can perform
77 to reliably determine EOF (for example a MIME boundary).