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:
cStream = New CryptoStream(input, _ RijndaelAlg.CreateDecryptor(_key, IV), _ CryptoStreamMode.Read) Dim HeaderBuffer(4) As Byte cStream.Read(HeaderBuffer, 0, 5) If encoding.GetString(HeaderBuffer) <> HeaderString Then RaiseEvent ReturnType(ActionReturnType.InvalidPassword) cStream.Clear() Exit Try End If Do While BytesProcessed < SourceLength CurrentBytes = cStream.Read(Buffer, 0, 4096) output.Write(Buffer, 0, CurrentBytes) BytesProcessed += CLng(CurrentBytes) PercentDone = CInt((BytesProcessed / SourceLength) * 100) RaiseEvent Progress(PercentDone) 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.




.

Reply With Quote