This post here talks about decoding a base64 string to an unsigned char
(uint8_t
) array. There's a lot there, and it also seems someone took the code there and posted it here (or vice-verca.)
After looking at all these threads and options (as mentioned above there's a lot of tools out there for this), I used the open source one from Apple's open source libraries. There are many issues with the various code snippets posted in the other SO post that dissuaded me so I decided to stick with the one from Apple since it looked quite clean and has good provenance. I tested it out with a some base64 strings I converted with this online tool and it was all correct.
You need to replace #include "lib.h"
with:
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
And then make a quick base64.h
to include (the one I found on Apple's open source didn't seem to match)
#ifndef _BASE64_H_
#define _BASE64_H_
#ifdef __cplusplus
extern "C" {
#endif
size_t base64_decode(char *source, unsigned char *target, size_t targetlen);
int base64_encode(unsigned char *source, size_t sourcelen, char *target, size_t targetlen);
#ifdef __cplusplus
}
#endif
#endif //_BASE64_H_