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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Then why not post to the vb.net group? I think the problem is that
the FlushFinalBlock() method is used by the writer after data is
written to the stream, to ensure that the data buffer has been
properly flushed. It should not be used by the reader when data is
read from the stream. When you call it here, it has already been
called by whatever wrote the data to the stream, thus the error
message. Try removing the FlushFinalBlock() method, and the error
should go away.
Rich Blum
Author of "C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176