Base64编码

编码:

std::string Base64EncryptStr(std::string plaintext)
{
	std::string outstr;

	Base64Encoder encoder;
	encoder.Put((byte*)plaintext.c_str(), plaintext.length());
	encoder.MessageEnd();

	word64 size = encoder.MaxRetrievable();
	if(size)
	{
		outstr.resize(size);		
		encoder.Get((byte*)outstr.data(), outstr.size());
	}

	return outstr;
}

解码:

std::string CCryptoEnvelop::Base64EncryptStr(std::string plaintext)
{
	std::string outstr;

	Base64Encoder encoder;
	encoder.Put((byte*)plaintext.c_str(), plaintext.length());
	encoder.MessageEnd();

	word64 size = encoder.MaxRetrievable();
	if(size)
	{
		outstr.resize(size);		
		encoder.Get((byte*)outstr.data(), outstr.size());
	}

	return outstr;
}
本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院