BIO_F_BASE64(3)
π BIO_F_BASE64(3) π
okay so this is a page from the Library Functions Manual (libcrypto division, we love her) and it's all about the base64 BIO filter. buckle up bestie, it's actually so good.
β¨ NAME β¨
BIO_f_base64 β the base64 BIO filter, aka the girly who encodes and decodes for you π
πΈ SYNOPSIS πΈ
library βlibcryptoβ #include <openssl/bio.h>
#include <openssl/evp.h>
const BIO_METHOD *
BIO_f_base64(void);
π¦ DESCRIPTION π¦
So BIO_f_base64() returns the base64 BIO method. it's a filter BIO, which means it sits there and base64 encodes any data you write through it, and decodes any data you read through it. it's giving translator. it's giving bilingual icon. periodt π
heads up bestie: base64 BIOs do not supportBIO_gets(3)orBIO_puts(3). like, at all. not their thing. π
BIO_flush(3) on a base64 BIO that you're writing through is how you signal "okay that's it, no more data to encode" β it's literally what flushes that final block through the BIO. think of it as the "and that's a wrap" moment β¨
Now, if you want to encode all the data on one line and also expect the data to all be on one line, you set up your base64 BIO like this:
BIO *b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
no newlines, no drama, just vibes π
π RETURN VALUES π
BIO_f_base64() returns the base64 BIO method. that's it, that's the return value π
And when you call BIO_method_type(3) on a base64 BIO object, it hands you back the constant BIO_TYPE_BASE64. meanwhile BIO_method_name(3) returns a pointer to the static string "base64 encoding". iconic string, no notes π«Ά
π₯ EXAMPLES π₯
Example 1: base64 encode the string "hello, world\n" and write the result to standard output. slay:
BIO *bio, *b64;
char message[] = "hello, world\n";
b64 = BIO_new(BIO_f_base64());
bio = BIO_new_fp(stdout, BIO_NOCLOSE);
BIO_push(b64, bio);
BIO_write(b64, message, strlen(message));
BIO_flush(b64);
BIO_free_all(b64);
Example 2: read Base64-encoded data from standard input and write the decoded data to standard output. the way this one just works π:
BIO *bio, *b64, *bio_out;
char inbuf[512];
int inlen;
b64 = BIO_new(BIO_f_base64());
bio = BIO_new_fp(stdin, BIO_NOCLOSE);
bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
BIO_push(b64, bio);
while((inlen = BIO_read(b64, inbuf, 512)) > 0)
BIO_write(bio_out, inbuf, inlen);
BIO_flush(bio_out);
BIO_free_all(b64);
π§ SEE ALSO π§
go read those next, iykyk π
β HISTORY β
BIO_f_base64() first appeared in SSLeay 0.6.5 and has been available since OpenBSD 2.4. she's been around. she's a legacy queen π
π BUGS π
okay so this part is lowkey a mess, ngl:
- the ambiguity of EOF in base64-encoded data can cause additional data following the base64-encoded block to be misinterpreted. yeah. that's a real thing. π«
- there should be some way of specifying a test that the BIO can perform to reliably determine EOF (for example, a MIME boundary). as of right now, there just isn't. fr fr.
tl;dr: EOF detection in base64 land is kinda giving chaos and the manpage itself is asking for a fix π
and that's the whole page bestie!! this one's from the Debian crew, dated June 8, 2025 β go forth and base64 responsibly πβ¨π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2003, 2005, 2014 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms