https://www.cryptopp.com/wiki/StreamTransformationFilter
和
https://www.cryptopp.com/wiki/CBC_Mode
排队
StringSource string_source(encypted_data, true, new StreamTransformationFilter(decryption, new StringSink(plain_data)));
new
运算符;但是我们不会删除它们。它不应该导致内存泄漏,因为他们没有删除操作。
我要换吗
StringSource string_source(plain_data, true, new StreamTransformationFilter(encryption, new StringSink(encypted_data)));
使用以下代码
try
{
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption encryption(this->aes_key.data(), this->aes_key.size(), this->aes_iv.data(), this->aes_iv.size())
CryptoPP::StringSink string_sink(encypted_data);
CryptoPP::StreamTransformationFilter stf_encryptor(encryption, string_sink);
CryptoPP::StringSource string_source(plain_data, true, stf_encryptor);
}
CryptoPP::StringSink
,
CryptoPP::StreamTransformationFilter
和
CryptoPP::StringSource
课程:
std::optional<std::string> Cryptography::decrypt_data(const std::string& encypted_data)
{
std::optional<std::string> plain_data { std::nullopt };
try
{
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decryption(this->aes_key.data(), this->aes_key.size(), this->aes_iv.data(), this->aes_iv.size())
StringSource string_source(encypted_data, true, new StreamTransformationFilter(decryption, new StringSink(plain_data)));
}
catch(const CryptoPP::Exception& e)
{
#ifdef _DEBUG
spdlog::error("CryptoPP Exception in Cryptography::decrypt_data : {}", ex.what());
#endif
PLOG_ERROR << ex.what();
}
catch(const std::exception& ex)
{
#ifdef _DEBUG
spdlog::error("Exception in Cryptography::decrypt_data : {}", ex.what());
#endif
PLOG_ERROR << ex.what();
}
return plain_data;
}