openssl库中的加密工具可以对数据进行简单的加解密,代码如下所示:
1 #include <stdio.h> 2 #include <string.h> 3 #include <unistd.h> 4 5 #include <openssl/pem.h> 6 #include <openssl/bio.h> 7 #include <openssl/evp.h> 8 9 int base64_encode(char *in_str, int in_len, char *out_str) 10 { 11 BIO *b64, *bio; 12 BUF_MEM *bptr = NULL; 13 size_t size = 0; 14 15 if (in_str == NULL || out_str == NULL) 16 return -1; 17 18 b64 = BIO_new(BIO_f_base64()); 19 bio = BIO_new(BIO_s_mem()); 20 bio = BIO_push(b64, bio); 21 22 BIO_write(bio, in_str, in_len); 23 BIO_flush(bio); 24 25 BIO_get_mem_ptr(bio, &bptr); 26 memcpy(out_str, bptr->data, bptr->length); 27 out_str[bptr->length] = '