0

要计算 base64,我使用以下代码:

#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;
}

但它不仅返回大多数函数已被弃用的警告,例如'BIO_ctrl' is deprecated: first deprecated in OS X 10.7,而且由于 Undefined symbols for architecture x86_64: "_BIO_ctrl".

我还能如何在 base64 中编码字符串?

没有工作代码如何在 C 中进行 base64 编码(解码)?

4

0 回答 0