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