1.\" $OpenBSD: BIO_f_base64.3,v 1.11 2019/06/06 01:06:58 schwarze Exp $ 2.\" OpenSSL fc1d88f0 Wed Jul 2 22:42:40 2014 -0400 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2000, 2003, 2005, 2014 The OpenSSL Project. 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in 17.\" the documentation and/or other materials provided with the 18.\" distribution. 19.\" 20.\" 3. All advertising materials mentioning features or use of this 21.\" software must display the following acknowledgment: 22.\" "This product includes software developed by the OpenSSL Project 23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24.\" 25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26.\" endorse or promote products derived from this software without 27.\" prior written permission. For written permission, please contact 28.\" openssl-core@openssl.org. 29.\" 30.\" 5. Products derived from this software may not be called "OpenSSL" 31.\" nor may "OpenSSL" appear in their names without prior written 32.\" permission of the OpenSSL Project. 33.\" 34.\" 6. Redistributions of any form whatsoever must retain the following 35.\" acknowledgment: 36.\" "This product includes software developed by the OpenSSL Project 37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38.\" 39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51.\" 52.Dd $Mdocdate: June 6 2019 $ 53.Dt BIO_F_BASE64 3 54.Os 55.Sh NAME 56.Nm BIO_f_base64 57.Nd base64 BIO filter 58.Sh SYNOPSIS 59.In openssl/bio.h 60.In openssl/evp.h 61.Ft const BIO_METHOD * 62.Fo BIO_f_base64 63.Fa void 64.Fc 65.Sh DESCRIPTION 66.Fn BIO_f_base64 67returns the base64 BIO method. 68This is a filter BIO that base64 encodes any data written through it 69and decodes any data read through it. 70.Pp 71Base64 BIOs do not support 72.Xr BIO_gets 3 73or 74.Xr BIO_puts 3 . 75.Pp 76.Xr BIO_flush 3 77on a base64 BIO that is being written through 78is used to signal that no more data is to be encoded: 79this is used to flush the final block through the BIO. 80.Pp 81To encode the data all on one line and to expect the data to be all 82on one line, initialize the base64 BIO as follows: 83.Bd -literal -offset indent 84BIO *b64 = BIO_new(BIO_f_base64()); 85BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); 86.Ed 87.Sh RETURN VALUES 88.Fn BIO_f_base64 89returns the base64 BIO method. 90.Sh EXAMPLES 91Base64 encode the string "Hello World\en" 92and write the result to standard output: 93.Bd -literal -offset indent 94BIO *bio, *b64; 95char message[] = "Hello World \en"; 96 97b64 = BIO_new(BIO_f_base64()); 98bio = BIO_new_fp(stdout, BIO_NOCLOSE); 99BIO_push(b64, bio); 100BIO_write(b64, message, strlen(message)); 101BIO_flush(b64); 102 103BIO_free_all(b64); 104.Ed 105.Pp 106Read Base64-encoded data from standard input 107and write the decoded data to standard output: 108.Bd -literal -offset indent 109BIO *bio, *b64, *bio_out; 110char inbuf[512]; 111int inlen; 112 113b64 = BIO_new(BIO_f_base64()); 114bio = BIO_new_fp(stdin, BIO_NOCLOSE); 115bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); 116BIO_push(b64, bio); 117while((inlen = BIO_read(b64, inbuf, 512)) > 0) 118 BIO_write(bio_out, inbuf, inlen); 119 120BIO_flush(bio_out); 121BIO_free_all(b64); 122.Ed 123.Sh SEE ALSO 124.Xr BIO_new 3 , 125.Xr EVP_EncodeInit 3 126.Sh HISTORY 127.Fn BIO_f_base64 128first appeared in SSLeay 0.6.5 and has been available since 129.Ox 2.4 . 130.Sh BUGS 131The ambiguity of EOF in base64-encoded data can cause additional 132data following the base64-encoded block to be misinterpreted. 133.Pp 134There should be some way of specifying a test that the BIO can perform 135to reliably determine EOF (for example a MIME boundary). 136