【问题标题】:Botan AES CBC PKCS7 encryption and decryptionBotan AES CBC PKCS7 加解密
【发布时间】:2017-10-11 09:27:48
【问题描述】:

我现在正在使用 Botan 库。

我想使用 PKCS7 填充模式使用 AES/CBC 模式加密我的文件。

Botan提供的AES/CBC解密在出错时会抛出异常,不确定是否容易受到padding oracle攻击。

那么我应该如何执行解密过程来防止攻击呢?

更新:

  1. 即使我不返回填充错误,文件也会保持不变,这可以被攻击者知道。

  2. 我的代码如下:(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


【解决方案1】:

使用随机IV的CBC模式,只需在加密数据前加上IV用于解密即可,不需要保密。不需要传入IV,让加密函数创建一个随机IV。

【讨论】:

  • 这是否意味着我有责任保护文件不被他人篡改?
  • 您需要提供随机IV。如果您担心篡改,则需要添加身份验证,您需要提供用例和威胁评估,即您要保护的对象、他们具有哪些功能以及货币单位或声誉的价值:没有加密100% 安全,但可以非常接近。
猜你喜欢
  • 2013-08-11
  • 2015-06-24
  • 1970-01-01
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-05
  • 1970-01-01
相关资源
最近更新 更多