小编Sim*_*ose的帖子

解密加密文本文件内容并将其复制到MemoryStream

我试图将文本文件的加密内容复制到内存流中,然后解密这些内容并将其复制到新的内存流中。当我到达发生复制的代码时,我在调试时收到无效数据错误。

这是我得到的代码块:

Function DecryptFile(ByVal sInputFilename As String, ByVal sKey As String) As Byte()

    Dim DES As New DESCryptoServiceProvider()

    DES.Key() = ASCIIEncoding.ASCII.GetBytes(sKey)
    DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)

    Dim desdecrypt As ICryptoTransform = DES.CreateDecryptor()

    Dim encryptedByteArray() As Byte
    encryptedByteArray = File.ReadAllBytes(sInputFilename)

    Dim encryptedMS As MemoryStream = New MemoryStream(encryptedByteArray)
    Dim cryptostreamDecr As New CryptoStream(encryptedMS, desdecrypt, CryptoStreamMode.Read)
    Dim decryptedMS As MemoryStream = New MemoryStream()

    cryptostreamDecr.CopyTo(decryptedMS) 'Error occurs here
    cryptostreamDecr.Close()

    Return decryptedMS.ToArray()
End Function
Run Code Online (Sandbox Code Playgroud)

我正在关注散布在网络上的示例,从我读过的内容来看,这段代码应该可以工作......

谁能向我解释我做错了什么?

vb.net encryption des tripledes

1
推荐指数
1
解决办法
159
查看次数

标签 统计

des ×1

encryption ×1

tripledes ×1

vb.net ×1