我正在使用 Crypto++ 来满足其他加密需求;但是,我还需要将二进制信息存储为 ascii 文本。为此,我将 Crypto++ 的 base 64 过滤器的示例合成到以下代码块中。
bool saveData(const unsigned char * buffer, size_t length)
{
int lenb64 = (ceil(length / 3.0) * 4) + 1;
unsigned char * temp_str = (unsigned char *)malloc(lenb64);
CryptoPP::ArraySource as(buffer, length, new CryptoPP::Base64Encoder(
new CryptoPP::ArraySink(temp_str, lenb64)));
//do something with temp_str.
free(temp_str); //Then free the tempstr.
//Return true if do something worked, else false.
}
我遇到的问题是,在此操作之后 temp_str 仍然充满垃圾。我环顾四周,除了我上面所做的之外,找不到任何其他示例。有什么我想念的吗?