End of Stream encountered...

Status
Niet open voor verdere reacties.

SuperABC

Gebruiker
Lid geworden
16 jul 2009
Berichten
327
Hi,

Ik krijg deze fout:
Code:
End of Stream encountered before parsing was completed.
Bij deze code:
Code:
        Dim BinFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Output_Graph = BinFormatter.Deserialize(FS)

De Stream: FS bevat wel degelijk informatie, als je op internet zoekt zeggen ze:
Code:
FS.Position = 0
Maar helaas helpt dat niets want dan heb je:
Code:
Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.

Weet iemand hier een geschikte oplossing voor?!:thumb:
 
Nog meer ter aanvulling want het lijkt erop dat het half niet werkt:
Deze kan Encrypt wel goed, maar de Decrypte lijkt niet goed te werken... Misschien kan iemand me helpen ik heb al vanalles geprobeerd:(

Code:
Public Sub Decrypt(ByVal Output_Graph As Object, ByVal Input_Path As String)
        Dim Key As Byte()
        Dim IV As Byte()
        Key = CreateKey("SuperABC123")
        IV = CreateIV("SuperABC123")

        Dim Input As New IO.FileStream(Input_Path, FileMode.Open, FileAccess.Read)
        Dim FS As New IO.MemoryStream()

        Dim bytBuffer(Input.Length) As Byte
        Dim csCryptoStream As CryptoStream
        Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged

        csCryptoStream = New CryptoStream(FS, _
        cspRijndael.CreateDecryptor(Key, IV), _
        CryptoStreamMode.Write)

[COLOR="Red"]        Input.Read(bytBuffer, 0, Input.Length)
        csCryptoStream.Write(bytBuffer, 0, Input.Length)[/COLOR]

        Dim BinFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Output_Graph = BinFormatter.Deserialize(FS)

        csCryptoStream.Close()
        FS.Close()
        Input.Close()
    End Sub
Code:
 Public Sub Encrypt(ByVal Input_Graph As Object, ByVal Output_Path As String)
        Dim Output As New IO.FileStream(Output_Path, FileMode.Create)

        Dim BinFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Dim FS As New IO.MemoryStream()
        BinFormatter.Serialize(FS, Input_Graph)

        Dim Key As Byte()
        Dim IV As Byte()
        Key = CreateKey("SuperABC123")
        IV = CreateIV("SuperABC123")

        Dim bytBuffer(FS.Length) As Byte
        Dim csCryptoStream As CryptoStream
        Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged

        csCryptoStream = New CryptoStream(Output, _
        cspRijndael.CreateEncryptor(Key, IV), _
        CryptoStreamMode.Write)

        FS.Read(bytBuffer, 0, FS.Length)
        csCryptoStream.Write(bytBuffer, 0, FS.Length)

        csCryptoStream.Close()
        FS.Close()
        Output.Close()
    End Sub

Volgens mij gaat het bij het rode fout, nadat ik het naar het file heb laten schrijven blijkt het (wat gedoceerd moest worden) precies hetzelfde te zijn als het input bestand...

CreateKey, CreateIV zitten wel goed...
 
Laatst bewerkt:
Als ik bij de DeCrypt van de MemoryStream, FS een FileStream maakt, werkt het wel goed... Weet iemand hoe dit komt, en hoe ik kan zorgen dat het toch ook werkt voor een MemoryStream?

Tevens werkt het nog beter als ik het zo doe:

Code:
    Public Sub Decrypt(ByVal Output_Graph As Object, ByVal Input_Path As String)
        Dim Key As Byte()
        Dim IV As Byte()
        Key = CreateKey("SuperABC123")
        IV = CreateIV("SuperABC123")

        Dim Input As New IO.FileStream(Input_Path, FileMode.Open, FileAccess.Read)

        'Dim FS As New IO.FileStream(Path_App & "\qwerty.txt", FileMode.Create)

        Dim bytBuffer(Input.Length) As Byte
        Dim csCryptoStream As CryptoStream
        Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged

        Input.Position = 0

        Input.Read(bytBuffer, 0, Input.Length)

        Dim FS As New IO.MemoryStream(bytBuffer)

        csCryptoStream = New CryptoStream(FS, _
        cspRijndael.CreateDecryptor(Key, IV), _
        CryptoStreamMode.Write)

        csCryptoStream.Write(bytBuffer, 0, Input.Length)

        Dim wr As New IO.FileStream(Path_App & "\abcxyz.txt", FileMode.Create)
        wr.Write(bytBuffer, 0, Input.Length)

        'Dim BinFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        'Output_Graph = BinFormatter.Deserialize(FS)

        csCryptoStream.Close()
        FS.Close()
        Input.Close()
    End Sub

Maar het resultaat is slechts half goed...
Misschien komt het doordat het niet-gecodeerde bestand = 36 Bytes
Het wel-gecodeerde bestand = 48 Bytes
 
Laatst bewerkt:
Ik Encrypt de string: Visual Basic.NET
De output is dit:

Code:
Ž.Û©az\‰÷›¼%DïÍ•:&-ÞØWëú-,[COLOR="Red"]§€í£‘–ebR“z9ð[/COLOR]

Als ik het proces omdraai is de output dit:

Code:
    ÿÿÿÿ          Visual Ba[COLOR="red"]§€í£‘–ebR“z9ð[/COLOR]

Wat gaat er in de laatst geposte Encrypt code fout, dat er zo'n halve output uitkomt?
Dat ÿÿÿÿ e.d. komt doordat het object geserializeerd is
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan