【发布时间】:2017-10-11 09:27:48
【问题描述】:
我现在正在使用 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; } }
【问题讨论】:
-
1.为了避免填充 oracle 攻击,不要返回填充错误。 2. 你没有提供你是如何使用加密的,这会影响填充预言攻击是否可能。
-
@zaph 感谢您的回复。我已经更新了我的问题。
-
No 1 不清楚,没有密钥的加密文件是安全的。
-
使用带有随机IV的CBC模式,只需在加密数据前加上IV用于解密即可,不需要保密。不需要传入IV,让加密函数创建一个随机IV。
标签: c++ cryptography aes cbc-mode botan