⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base64src.cpp

📁 C++ Base64编码/解码源代码 inline int Base64Encode(char * base64code, const char * src, int src_len = 0)
💻 CPP
字号:
// base64src.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "string.h"
#include "base64.h"
#include "conio.h"

// 参考文章:http://www.cstc.net.cn/docs/docs.php?id=202


const char * pTextDemo = 
"你好,SnaiX\r\n"
"\r\n"
"  这是一个Base64的测试邮件!\r\n"
"\r\n"
"Best Wishes!\r\n"
"\r\n"
"                             eSX?!\r\n"
"                             snaix@yeah.net\r\n"
"                          2003-12-25"
;

const char * p64 = 
"xOO6w6OsU25haVgNCg0KoaGhodXiysfSu7j2QmFzZTY0tcSy4srU08q8/qOhDQoNCkJlc3QgV2lz" 
"aGVzIQ0KIAkJCQkNCqGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaEgICAgICAgICAgICAgICBl" 
"U1g/IQ0KoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoSAgICAgICAgICAgICAgIHNuYWl4QHll" 
"YWgubmV0DQqhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhICAgICAgICAgMjAwMy0x" 
"Mi0yNQ0K";

int main(int argc, char* argv[])
{
//	printf("Hello World!\n");

	int len = strlen(pTextDemo);
	
	char* pBase64 = new char[len * 2 + 4];
	// 编码后的长度一般比原文多占1/3的存储空间,请保证pBase64有足够的空间
	int len_b64 = Base64Encode(pBase64, pTextDemo);
	printf("[Base64]:\r\n%s\r\n\r\n", pBase64);

	char* pszSrc = new char[len + 1];
	int len_src = Base64Decode(pszSrc, pBase64);
	printf("[源文]:\r\n%s\r\n\r\n", pszSrc);

	delete [] pszSrc;
	delete [] pBase64;

	getch();

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -