Я пытался выяснить документацию openssl для декодирования и кодирования base64. Я нашел несколько фрагментов кода ниже
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
char *base64(const unsigned char *input, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
char *buff = (char *)malloc(bptr->length);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
char *decode64(unsigned char *input, int length)
{
BIO *b64, *bmem;
char *buffer = (char *)malloc(length);
memset(buffer, 0, length);
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf(input, length);
bmem = BIO_push(b64, bmem);
BIO_read(bmem, buffer, length);
BIO_free_all(bmem);
return buffer;
}
Кажется, что это работает только для строк с одной строкой, таких как "Пуск", в тот момент, когда я вводил сложные строки с символами новой строки и пробелами и т.д., это терпит неудачу.
Это даже не должно быть openssl, простой класс или набор функций, которые делают то же самое, будут в порядке, theres очень сложный процесс сборки для решения, и я стараюсь избежать необходимости туда и внести несколько изменений. Единственная причина, по которой я пошел на openssl, - это то, что решение уже скомпилировано с библиотеками.