【问题标题】:decrypt and encrypt a file解密和加密文件
【发布时间】:2016-03-30 08:03:55
【问题描述】:

我正在尝试使用以下代码加密和解密文件。 https://msdn.microsoft.com/en-us/library/windows/desktop/aa382044(v=vs.85).aspx 加密链接仅提供给此链接。 当我试图解密文件时。已使用给定的链接加密。它只是解密一个数据块而不是完整的文件。 如果我改变 dwBlockLen = 1000000 - 1000000 % ENCRYPT_BLOCK_SIZE;然后它可以工作,但一次仍然是一个块。

我需要让它在代码中给出的 do while 语句中工作。这样它就可以立即读取数据块并对其进行解密。

【问题讨论】:

  • 那么是什么阻止了你?这听起来像是一个问题,而不是一个问题。

标签: c++ visual-c++ encryption


【解决方案1】:

不需要更改dwBlockLen 的值(不会解决问题)。 dwBlockLen 的值决定了一次读取的数据量。 While 循环用于读取完整的源文件。退出while循环的条件是:

 if(Amount of data read from file < dwBlockLen)

这意味着没有更多数据要读取并且循环退出。

您必须在下面的代码中调试条件 `if(dwCount

   // Decrypt the source file, and write to the destination file. 
    bool fEOF = false;
    do
    {
        //-----------------------------------------------------------
        // Read up to dwBlockLen bytes from the source file. 
        // ...
        if(dwCount <= dwBlockLen)
        {
            fEOF = TRUE;
        }

        //-----------------------------------------------------------
        // Decrypt the block of data. 
        // ...
        //-----------------------------------------------------------
        // Write the decrypted data to the destination file. 
        // ...
        //-----------------------------------------------------------
        // End the do loop when the last block of the source file 
        // has been read, encrypted, and written to the destination 
        // file.
    }while(!fEOF);

【讨论】:

  • 需要检查条件 if(dwCount == dwBlockLen) else 设为 false 以便 crydecrypt 函数知道这是要解密的最后一个块
猜你喜欢
  • 1970-01-01
  • 2021-10-20
  • 2017-02-03
  • 2013-11-19
  • 2019-03-04
  • 1970-01-01
  • 2011-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多