我现在正在使用 Botan 库。
我想使用 PKCS7 填充模式使用 AES/CBC 模式加密我的文件。
Botan 提供的 AES/CBC 解密在发生错误时会抛出异常,我不确定它是否容易受到 padding oracle 攻击。
那么我应该如何执行解密过程来防止攻击呢?
更新:
即使我不返回填充错误,文件也会保持不变,攻击者可以知道这一点。
我的代码如下:(将适当设置iv和key)
void encrypt(std::istream &in, std::ostream &out) { try { Botan::SymmetricKey key_t(key); Botan::InitializationVector iv_t(iv); Botan::Pipe encryptor(Botan::get_cipher(cipher_mode, key_t, iv_t, Botan::ENCRYPTION), new Botan::DataSink_Stream(out)); encryptor.start_msg(); in >> encryptor; encryptor.end_msg(); // flush buffers, complete computations } catch(...) { throw; } } void decrypt(std::istream &in, std::ostream &out) { try { Botan::SymmetricKey key_t(key); Botan::InitializationVector iv_t(iv); Botan::Pipe decryptor(Botan::get_cipher(cipher_mode, key_t, iv_t, Botan::DECRYPTION), new Botan::DataSink_Stream(out)); decryptor.start_msg(); in >> decryptor; decryptor.end_msg(); // flush buffers, complete computations } catch(...) { throw; } }