我正在使用以下功能通过RSA加密我的消息。但是,此函数返回一个字符串值,并且包含不可打印的字节。
string RSAencrypt(RSA::PublicKey publicKey,string plain) {
string cipher;
try {
AutoSeededRandomPool rng;
RSAES_OAEP_SHA_Encryptor e(publicKey);
StringSource ss1(plain, true,
new PK_EncryptorFilter(rng, e,
new StringSink(cipher)
) // PK_EncryptorFilter
); // StringSource
}
catch (CryptoPP::Exception & e)
{
cerr << "Caught Exception..." << endl;
cerr << e.what() << endl;
}
return cipher;
}
如何生成可打印字节?
new HexEncoder(
new StringSink(encoded)
) // HexEncoder
main page的第二行,还有从底部第二行列出的其他各种编码器。 Base64Encoder
最有意义。