2

CryptoStream用于在我的应用程序中解密加密文本。但是,当我从流中刷新最后一个块或关闭它(应该这样做)时,应用程序将关闭。

没有错误信息,什么都没有。即使在调试模式下,它也只是结束。在 Windows 事件查看器中,我得到.NET Runtime version 2.0.50727.5485 - Fatal Execution Engine Error (000007FEECCD600A) (80131506). 我的目标是使用该应用程序的框架 2.0。

这是我的代码:

    Public Function DecryptData(ByVal encryptedtext As String) As String
    Try
        ' Convert the encrypted text string to a byte array. 
        Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)

        ' Create the stream. 
        Dim ms As New System.IO.MemoryStream
        ' Create the decoder to write to the stream. 
        Dim decStream As New CryptoStream(ms, TripleDes.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write)

        ' Use the crypto stream to write the byte array to the stream.
        decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
        decStream.FlushFinalBlock()

         ' Convert the plaintext stream to a string. 
        Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
    Catch ex As System.Security.Cryptography.CryptographicException
        Return ""
    End Try
End Function

我尝试用 替换decStream.FlushFinalBlock()decStream.Close()得到了同样的结果。当我将其注释掉时,它返回的字符串仅包含 8 个字符的倍数。卡在最后一个区块中的剩余部分消失了。

所以我试图弄清楚为什么抓住最后一个流会关闭应用程序。我在源位置放了一个断点并使用 F11 进入它,但关闭是立即的。

我在 Windows 7 Professional 64 位上使用 VS 2008。

4

1 回答 1

0

' 使用加密流将字节数组写入流。

    decStream.Write(encryptedBytes, 0, encryptedBytes.Length)

哦,我的.....最后一个参数>encrytedBytes.lengt<。我使用它太错误了现在我的代码就像

于 2016-02-06T18:00:04.343 回答