1=pod 2 3=head1 NAME 4 5BIO_f_base64 - base64 BIO filter 6 7=head1 SYNOPSIS 8 9=for comment multiple includes 10 11 #include <openssl/bio.h> 12 #include <openssl/evp.h> 13 14 const BIO_METHOD *BIO_f_base64(void); 15 16=head1 DESCRIPTION 17 18BIO_f_base64() returns the base64 BIO method. This is a filter 19BIO that base64 encodes any data written through it and decodes 20any data read through it. 21 22Base64 BIOs do not support BIO_gets() or BIO_puts(). 23 24For writing, output is by default divided to lines of length 64 25characters and there is always a newline at the end of output. 26 27For reading, first line should be at most 1024 28characters long. If it is longer then it is ignored completely. 29Other input lines can be of any length. There must be a newline 30at the end of input. 31 32This behavior can be changed with BIO_FLAGS_BASE64_NO_NL flag. 33 34BIO_flush() on a base64 BIO that is being written through is 35used to signal that no more data is to be encoded: this is used 36to flush the final block through the BIO. 37 38The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags(). 39For writing, it causes all data to be written on one line without 40newline at the end. 41For reading, it forces the decoder to process the data regardless 42of newlines. All newlines are ignored and the input does not need 43to contain any newline at all. 44 45=head1 NOTES 46 47Because of the format of base64 encoding the end of the encoded 48block cannot always be reliably determined. 49 50=head1 RETURN VALUES 51 52BIO_f_base64() returns the base64 BIO method. 53 54=head1 EXAMPLES 55 56Base64 encode the string "Hello World\n" and write the result 57to standard output: 58 59 BIO *bio, *b64; 60 char message[] = "Hello World \n"; 61 62 b64 = BIO_new(BIO_f_base64()); 63 bio = BIO_new_fp(stdout, BIO_NOCLOSE); 64 BIO_push(b64, bio); 65 BIO_write(b64, message, strlen(message)); 66 BIO_flush(b64); 67 68 BIO_free_all(b64); 69 70Read Base64 encoded data from standard input and write the decoded 71data to standard output: 72 73 BIO *bio, *b64, *bio_out; 74 char inbuf[512]; 75 int inlen; 76 77 b64 = BIO_new(BIO_f_base64()); 78 bio = BIO_new_fp(stdin, BIO_NOCLOSE); 79 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); 80 BIO_push(b64, bio); 81 while ((inlen = BIO_read(b64, inbuf, 512)) > 0) 82 BIO_write(bio_out, inbuf, inlen); 83 84 BIO_flush(bio_out); 85 BIO_free_all(b64); 86 87=head1 BUGS 88 89The ambiguity of EOF in base64 encoded data can cause additional 90data following the base64 encoded block to be misinterpreted. 91 92There should be some way of specifying a test that the BIO can perform 93to reliably determine EOF (for example a MIME boundary). 94 95=head1 COPYRIGHT 96 97Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved. 98 99Licensed under the OpenSSL license (the "License"). You may not use 100this file except in compliance with the License. You can obtain a copy 101in the file LICENSE in the source distribution or at 102L<https://www.openssl.org/source/license.html>. 103 104=cut 105