Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Excuse me, I have a program and I got some error. there Is error in "
cs.Write(bytBuffer, 0, intBytesInCurrentBlock)
" 'Stream does not support writing. Please help me for my studying. thank you, sorry for my bad English.

What I have tried:

Private Sub enkripataudekrip(ByVal inputfile As String, ByVal outputfile As String, ByVal secret As String, ByVal direction As aksikripto)

        Dim fsinput As New FileStream(inputfile, FileMode.Open, FileAccess.Read)
        Dim fsoutput As New FileStream(outputfile, FileMode.OpenOrCreate, FileAccess.Write)
        fsoutput.SetLength(0)
        Dim skey As String = "aaaaaaaa"
        Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
        Dim lngBytesProcessed As Long = 0 'running count of bytes processed
        Dim lngFileLength As Long = fsinput.Length 'the input file's length
        Dim intBytesInCurrentBlock As Integer 'current bytes being processed
        Dim cs As CryptoStream
        Dim des As New DESCryptoServiceProvider
        des.Key = ASCIIEncoding.ASCII.GetBytes(skey)
        des.IV = ASCIIEncoding.ASCII.GetBytes(skey)
        Select Case direction
            Case aksikripto.enkrip
                

                cs = New CryptoStream(fsoutput, des.CreateEncryptor, CryptoStreamMode.Write)
                'Dim bytearrayinput(fsinput.Length - 1) As Byte
                'fsinput.Read(bytearrayinput, 0, bytearrayinput.Length)
                'cs.Write(bytearrayinput, 0, bytearrayinput.Length)
                'cs.Close()

            Case aksikripto.dekrip
                'Dim des As New DESCryptoServiceProvider
                cs = New CryptoStream(fsinput, des.CreateDecryptor, CryptoStreamMode.Read)

                'Dim fsdekrip As New StreamWriter(outputfile)
                'fsdekrip.Write(New StreamReader(csdec).ReadToEnd)
                'fsdekrip.Flush()
                'fsdekrip.Close()
        End Select

        While lngBytesProcessed < lngFileLength
            intBytesInCurrentBlock = fsinput.Read(bytBuffer, 0, 4096)
            cs.Write(bytBuffer, 0, intBytesInCurrentBlock) 'Stream does not support writing

        End While

        cs.Close()
        fsinput.Close()
        fsoutput.Close()

    End Sub
Posted
Updated 5-Feb-17 10:50am

1 solution

You create cs as a read or write cryptostream based on the direction read or write, you then write to cs regardless of whether it is a read or write operation, likely the read version of cs cannot write.
 
Share this answer
 
Comments
Member 11905957 6-Feb-17 9:53am    
Yaeh finally, I understood Sir Thank You..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900