FlushFinalBlock() method was called twice on a CryptoStream

  • Thread starter Anil Gupte/iCinema.com
  • Start date
A

Anil Gupte/iCinema.com

I am getting the following message and no, it is not even going to that
statement twice. Why is this happening?


System.NotSupportedException was caught
Message="FlushFinalBlock() method was called twice on a CryptoStream. It
can only be called once."
Source="mscorlib"
StackTrace:
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at TempCrypt.Crypt.DecryptString128Bit(String
vstrStringToBeDecrypted, String vstrDecryptionKey) in
D:\Projects\VB\TempCrypt\TempCrypt\Crypt.vb:line 132

TIA,
 
A

Anil Gupte/iCinema.com

Sorry, I meant to add this, here is the code that generates the error.

bytDataToBeDecrypted = Convert.FromBase64String(vstrStringToBeDecrypted)
bytDecryptionKey = Encoding.ASCII.GetBytes(vstrDecryptionKey.ToCharArray)
ReDim bytTemp(bytDataToBeDecrypted.Length)
objMemoryStream = New MemoryStream(bytDataToBeDecrypted)
objCryptoStream = New CryptoStream(objMemoryStream,
objRijndaelManaged.CreateDecryptor(bytDecryptionKey, bytIV),
CryptoStreamMode.Read)
objCryptoStream.Read(bytTemp, 0, bytTemp.Length)
Try
objCryptoStream.FlushFinalBlock() <-- It goes to the Catch statement from
here
objMemoryStream.Close()
objCryptoStream.Close()
Catch ex As Exception
MsgBox("DecryptString: " & ex.ToString)
End Try

Thanx,
 

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