This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <openssl/bio.h> | |
#include <openssl/evp.h> | |
void base64calc(const unsigned char* msg, size_t msgsize, char* out, size_t outsize) { | |
BIO *bio, *b64, *mem; | |
// Shit, this base64 thing with openssl was hard to get right. | |
b64 = BIO_new(BIO_f_base64()); | |
// No b64 newlines. | |
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); | |
mem = BIO_new(BIO_s_mem()); | |
bio = BIO_push(b64, mem); | |
BIO_write(bio, msg, msgsize); | |
BIO_flush(bio); | |
BIO_gets(mem, out, outsize); | |
BIO_free_all(bio); | |
} |