FlushFinalBlock() method was called twice on a CryptoStream

K

Khor Soon Hua

when i run the following code, the above error is occured. can anybody
help me? sorry cosz it is a vb.net code.

Public Function Decrypt(ByVal strToDecrypt As String) As String

Dim sb As New StringBuilder
Dim byteToDecrypt() As Byte = Convert.FromBase64String(strToDecrypt)
Dim byteDecoded(byteToDecrypt.Length) As Byte
Dim ms As New MemoryStream(byteToDecrypt)
Dim cs As CryptoStream

Try
byteKey = GetKey(strKey)
byteIV = GetKey(strIV)
Dim desProvider As New DESCryptoServiceProvider
cs = New CryptoStream(ms, desProvider.CreateDecryptor(byteKey,
byteIV), CryptoStreamMode.Read)
cs.Read(byteDecoded, 0, byteDecoded.Length)
cs.FlushFinalBlock()
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
ms.Close()
cs.Close()
End Try

Dim intLength As Integer = byteDecoded.Length - 1
For i As Integer = 0 To intLength
sb.Append(byteDecoded(i).ToString)
Next
Return sb.ToString
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top