Skip to content

Instantly share code, notes, and snippets.

@alejolp
Created February 26, 2014 22:11
Show Gist options
  • Save alejolp/9239685 to your computer and use it in GitHub Desktop.
Save alejolp/9239685 to your computer and use it in GitHub Desktop.
#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);
}
@IsraelBuitronD
Copy link

Thank you for you gist...

I copy and compile it, but it throws me deprecation warnings:

gcc-4.6 -Wall -std=c99 -g -c pathgraph2pem.c
pathgraph2pem.c: In function 'base64calc':
pathgraph2pem.c:33:5: warning: 'BIO_new' is deprecated (declared at /usr/include/openssl/bio.h:591) [-Wdeprecated-declarations]
pathgraph2pem.c:33:5: warning: 'BIO_f_base64' is deprecated (declared at /usr/include/openssl/evp.h:647) [-Wdeprecated-declarations]
pathgraph2pem.c:36:5: warning: 'BIO_set_flags' is deprecated (declared at /usr/include/openssl/bio.h:208) [-Wdeprecated-declarations]
pathgraph2pem.c:37:5: warning: 'BIO_new' is deprecated (declared at /usr/include/openssl/bio.h:591) [-Wdeprecated-declarations]
pathgraph2pem.c:37:5: warning: 'BIO_s_mem' is deprecated (declared at /usr/include/openssl/bio.h:626) [-Wdeprecated-declarations]
pathgraph2pem.c:38:5: warning: 'BIO_push' is deprecated (declared at /usr/include/openssl/bio.h:604) [-Wdeprecated-declarations]
pathgraph2pem.c:39:5: warning: 'BIO_write' is deprecated (declared at /usr/include/openssl/bio.h:597) [-Wdeprecated-declarations]
pathgraph2pem.c:40:5: warning: 'BIO_ctrl' is deprecated (declared at /usr/include/openssl/bio.h:600) [-Wdeprecated-declarations]
pathgraph2pem.c:40:5: warning: value computed is not used [-Wunused-value]
pathgraph2pem.c:41:5: warning: 'BIO_gets' is deprecated (declared at /usr/include/openssl/bio.h:596) [-Wdeprecated-declarations]
pathgraph2pem.c:42:5: warning: 'BIO_free_all' is deprecated (declared at /usr/include/openssl/bio.h:606) [-Wdeprecated-declarations]

Do you have some idea to fix/avoid these warnings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment