【问题标题】:Encryption and decryption corrupting binary files加密和解密损坏的二进制文件
【发布时间】:2016-06-05 18:44:28
【问题描述】:

我有两个简单的加密解密函数。这些功能适用于文本文件,我可以成功检索文件。但它会破坏二进制文件。如果我加密图像然后解密,它就会损坏。

bool Encrypter::FileEncrypter(std::string src, std::string dest)
{
    try {
        Botan::InitializationVector iv(enckey.substr(0,32));
        Botan::SymmetricKey symKey(enckey.substr(32,32));
        Botan::DataSource_Stream in(src.c_str(), true);
        Botan::Pipe enc(Botan::get_cipher("AES-128/CBC", symKey, iv, Botan::ENCRYPTION), new Botan::DataSink_Stream(dest.c_str()));
        enc.process_msg(in);
        return true;
    }
    catch(std::exception &e){
        return false;
    }

}

bool Encrypter::FileDecrypter(std::string src, std::string dest)
{
    try {
        Botan::InitializationVector iv(enckey.substr(0,32));
        Botan::SymmetricKey symKey(enckey.substr(32,32));
        Botan::DataSource_Stream in(src.c_str(), true);
        Botan::Pipe dec(Botan::get_cipher("AES-128/CBC", symKey, iv, Botan::DECRYPTION), new Botan::DataSink_Stream(dest.c_str()));
        dec.process_msg(in);
        return true;
    }
    catch(std::exception &e){
        return false;
    }

}

【问题讨论】:

    标签: c++ encryption cryptography botan


    【解决方案1】:

    API 说:

    DataSink_Stream (const std::string &pathname, bool use_binary=false)
    

    您可能希望将最后一个参数设置为 true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多