Last active
February 15, 2016 09:45
-
-
Save ksose/987c6a2f1e402ebe5d4b to your computer and use it in GitHub Desktop.
base64 encode openssl
This file contains hidden or 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
int Base64Encode(const unsigned char *buffer, size_t length, char **output) | |
{ | |
BIO *bio, *b64; | |
BUF_MEM *ptr; | |
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); | |
BIO_write(bio, buffer, length); | |
BIO_flush(bio); | |
BIO_get_mem_ptr(bio, &ptr); | |
BIO_set_close(bio, BIO_NOCLOSE); | |
BIO_free_all(bio); | |
*output = (char *)zalloc(ptr->length + 1); | |
memcpy(*output, ptr->data, ptr->length); | |
int len = ptr->length; | |
BUF_MEM_free(ptr); | |
return len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment