Hello...

I'm trying to read 5 bytes from a file and then do something according to what has been read. This is my code (I'll explain in a bit what's wrong):

vb.net Code:
  1. cStream = New CryptoStream(input, _
  2.                            RijndaelAlg.CreateDecryptor(_key, IV), _
  3.                            CryptoStreamMode.Read)
  4.  
  5.                     Dim HeaderBuffer(4) As Byte
  6.                     cStream.Read(HeaderBuffer, 0, 5)
  7.  
  8.                     If encoding.GetString(HeaderBuffer) <> HeaderString Then
  9.                         RaiseEvent ReturnType(ActionReturnType.InvalidPassword)
  10.                         cStream.Clear()
  11.                         Exit Try
  12.                     End If
  13.  
  14.                     Do While BytesProcessed < SourceLength
  15.                         CurrentBytes = cStream.Read(Buffer, 0, 4096)
  16.                         output.Write(Buffer, 0, CurrentBytes)
  17.                         BytesProcessed += CLng(CurrentBytes)
  18.                         PercentDone = CInt((BytesProcessed / SourceLength) * 100)
  19.                         RaiseEvent Progress(PercentDone)
  20.                     Loop

It reads the 5 bytes I added to the encrypted file, but I want the CryptoStream to start from the sixth value and then copy the original bytes into the decrypted file, but it gives me an error:

Padding is invalid and cannot be removed.

That's why I'm trying to make it read from the sixth value and then continue copying normally, but I'm stuck.

Any help will be greatly appreciated!

Thanks .