To calculate base64 I'm using the following code:
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
char* encode(const char* input) {
BIO* b64 = BIO_new(BIO_f_base64());
BIO* b_mem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, b_mem);
BIO_write(b64, input, sizeof(input));
BIO_flush(b64);
BUF_MEM* b_ptr;
BIO_get_mem_ptr(b64, &b_ptr);
char* buff = (char*) malloc(b_ptr->length);
memcpy(buff, b_ptr->data, b_ptr->length - 1);
buff[b_ptr->length - 1] = 0;
BIO_free_all(b64);
return buff;
}
But not only it returns warnings that most of the functions are deprecated such as 'BIO_ctrl' is deprecated: first deprecated in OS X 10.7
, but also doesn't compile because of
Undefined symbols for architecture x86_64: "_BIO_ctrl"
.
How else can I encode a string in base64?
No working code How do I base64 encode (decode) in C?