Last active
June 2, 2020 07:41
-
-
Save iaoedsz2008/0b6c986efc768637cbce6cd118f309bf to your computer and use it in GitHub Desktop.
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> | |
#include <openssl/buffer.h> | |
std::string base64_encode (const void* data, int len) | |
{ | |
std::string ret; | |
BIO * bio, *b64; | |
BUF_MEM* bufferPtr; | |
b64 = BIO_new (BIO_f_base64 ()); | |
bio = BIO_new (BIO_s_mem ()); | |
bio = BIO_push (b64, bio); | |
BIO_set_flags (bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line | |
BIO_write (bio, data, len); | |
BIO_flush (bio); | |
BIO_get_mem_ptr (bio, &bufferPtr); | |
ret = std::string (bufferPtr->data, bufferPtr->length); | |
BIO_set_close (bio, BIO_NOCLOSE); | |
BIO_free_all (bio); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment