2

是否有人必须使用 Crypto++ 使用由 linux dm-crypt 加密的 aes-cbc-essiv:sha256 解密文件?我尝试使用以下代码解密文件。但这是不正确的。有没有人有过经验?你能帮助我吗?非常感谢。

void decrypt_file(const char* password,
                  const char* inputFileName, const char* outputFileName)
{
    byte pass[ AES::BLOCKSIZE ];
    byte iv[16];
    byte head_file[16]; 
    memset(iv, 0, 16);

    try
    {
      StringSource(password, true,
        new HashFilter(*(new CryptoPP::SHA256),
          new ArraySink(pass,AES::BLOCKSIZE)));

      CryptoPP::AES::Decryption
        aesDecryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);

      CryptoPP::CBC_Mode_ExternalCipher::Decryption
        cbcDecryption( aesDecryption, iv );

      StreamTransformationFilter *decryptor =
        new StreamTransformationFilter(cbcDecryption,
          new FileSink(outputFileName),
          StreamTransformationFilter::BlockPaddingScheme::ZEROS_PADDING);

      FileSource(inputFileName, true, decryptor);
    }
    catch(CryptoPP::Exception &e)
    {
      printf("Exception \n");
      cout << "std::exception caught:" << endl << e.what();
      return;
    }
}
4

0 回答 0