Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Excuse me, I have a program and I got some error. there Is error in "ebytes" from my program, please help me for my studying. thank you, sorry for my bad English.

What I have tried:

Private Sub enkripfile(ByVal inputfile As String, ByVal outputfile As String, ByVal direction As aksikripto)
        'Dim fsinput As New FileStream(inputfile, FileMode.Open, FileAccess.Read)
        Dim fbytes As Byte()
        Dim ebytes As Byte()
        Dim fsoutput As New FileStream(outputfile, FileMode.Create, FileAccess.Write)
        Dim cs As New CryptoStream(fsoutput, ebytes, CryptoStreamMode.Write)
        Select Case direction
            Case aksikripto.enkrip
                bf.Key = System.Text.Encoding.UTF8.GetBytes("akrie")
                fbytes = File.ReadAllBytes(inputfile)
                ebytes = bf.EncodeBytes(fbytes)
                'Dim bfencrypt As ICryptoTransform = bf.EncodeBytes()
                'mycryptostream = New CryptoStream(fsoutput, bf.EncodeBytes, CryptoStreamMode.Write)

        End Select

    End Sub
Updated 4-Nov-16 9:19am
Richard Deeming 4-Nov-16 14:14pm    
The error is pretty clear - the second parameter to the CryptoStream constructor[^] needs to be an instance of a class that implements the ICryptoTransform interface[^].

You are passing in a byte array. A byte array does not implement that interface.
Member 11905957 5-Nov-16 10:24am    
so how to implement the ICryptoTransform to the CryptoStream constructor Sir? please help me Sir, thank you..
Member 11905957 4-Nov-16 14:29pm    
thank you Sir, what do you mean instance of a class Sir? sorry for my beginner

1 solution

what do you mean instance of a class Sir? sorry for my beginner
If you don't know what an instance is, then you are trying to run before you can walk: you need to go right back to the beginning and start understanding the basics.

Let's talk about cars for a moment. A Car is a vehicle that has four wheels, that you Drive by manipulating it's controls. But you can't drive a Car to the shops, because a Car is a general concept rather than a specific vehicle. You can drive "that car", or "this car", or "your car" (or even "my car" if I give you the keys) because each of those "variables" reference a specific vehicle. "Your car" is the Blue Ford, registration number "ABC 123" and "My car" is that Red Mercedes, registration number "XYZ 456". each of those vehicles is an instance of the generic class of Cars.
So in order to drive to the shops, you need to identify a specific instance of a Car that you are authorised (by possession of the keys) to Drive. In the real world you acquire that instance by begging, borrowing, buying, or stealing a specific vehicle.

In computer terms, you need the same thing - an instance of a class, and here things are a lot more clear cut: the only way to get an instance of the Car class is to create it via the New keyword:
Dim myCar As new Car("Mercedes", Color.Red, "XYZ 456")

When you create your CryptoStream, you are passing it an array of bytes when it specifically requires something else: CryptoStream Constructor (Stream, ICryptoTransform, CryptoStreamMode) (System.Security.Cryptography)[^]
You find an example of how to use it under the class description: CryptoStream Class[^]
But seriously: if you don't know the basics, then you should stop what you are doing and go right back to learning them first, or you are going to get horribly confused.
Share this answer

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