解密并加密文件

时间:2016-03-30 08:03:56

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

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

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

1 个答案:

答案 0 :(得分:0)

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

 if(Amount of data read from file < dwBlockLen)

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

你必须调试条件`if(dwCount&lt; = dwBlockLen)&#39;在下面的代码中,读取源文件时很可能存在问题。

   // 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);