用OpenSSL 做Base64 编解码(C++)

本文介绍了如何使用OpenSSL库在C++中实现Base64编码和解码。主要内容包括编码解码函数的实现,强调了在编码过程中去除换行的设置,以及解码时需要注意的字符计数问题。此外,还提到了Java SDK的Base64编解码默认不带换行的特点,并给出了openssl命令行工具进行Base64操作的例子。
摘要由CSDN通过智能技术生成

参考

1)http://www.ioncannon.net/programming/34/howto-base64-encode-with-cc-and-openssl/
2)http://www.ioncannon.net/programming/122/howto-base64-decode-with-cc-and-openssl/
3)http://stackoverflow.com/questions/12109960/openssl-base64-decoding-bio-read-returns-0
4)http://stackoverflow.com/questions/5288076/doing-base64-encoding-and-decoding-in-openssl-c


main.cpp

#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;

char * Base64Encode(const char* input, int length, bool with_new_line);
char * Base64Decode(char* input, int length, bool with_new_line);

int main(int argc, char* argv[])
{
	cout << "With new line? y/n ";
	string option;
	cin >> option;
	bool with_new_line = ( ("y" == option || "Y" == option) ? true : false );

	string enc_input = "Henry Alfred Kissinger is a German-born American writer, political scientist, diplomat, and businessman. A recipient of the Nobel Peace Prize, he served as National Security Advisor and later concurrently as Secretary of State in the administrations of Presidents Richard Nixon and Gerald Ford.";

	cout << endl << "To be encoded:" << endl << "~" << enc_input << "~" << endl << endl;
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值