Skip to content

Instantly share code, notes, and snippets.

@allanjos
Last active December 17, 2018 19:19
Show Gist options
  • Select an option

  • Save allanjos/167b8dabf3b745947e170c6cf9e62081 to your computer and use it in GitHub Desktop.

Select an option

Save allanjos/167b8dabf3b745947e170c6cf9e62081 to your computer and use it in GitHub Desktop.
libbase64 usage
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFERSIZE 1024
#include <b64/encode.h>
#include <b64/decode.h>
using namespace std;
int main()
{
char buffer_input[BUFFERSIZE] = "Sunrise doesn't last all morning\n"
"A cloudburst doesn't last all day\n"
"Seems my love is up and has left you with no warning\n"
"It's not always going to be this grey\n"
"All things must pass\n"
"All things must pass away";
fprintf(stderr, "INPUT: %s\n\n", buffer_input);
char buffer_output[BUFFERSIZE] = {'\0'};
char buffer_decoded[BUFFERSIZE] = {'\0'};
base64::encoder encoder;
encoder.encode(buffer_input, strlen(buffer_input), buffer_output);
fprintf(stderr, "ENCODED: %s\n\n", buffer_output);
base64::decoder decoder;
decoder.decode(buffer_output, strlen(buffer_output), buffer_decoded);
fprintf(stderr, "DECODED: %s\n", buffer_input);
return 0;
}
// Compile under FreeBSD
// c++ -I /usr/local/include base64-test.cpp -o base64-test -L /usr/local/lib -lb64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment