user3516240
user3516240

Reputation: 375

Value of type '1-dimensional array of byte' cannot be converted to a byte

I'm trying to pass values to a backgroundworker. I previously posted to ask how it could be done here. An answer directed me to this code, but I'm having issues trying to use it. Here's what I'm doing:

Class MyParameters
    Friend strInputFile As String
    Friend strOutputFile As String
    Friend bytKey As Byte
    Friend bytIV As Byte
    Friend Direction As New CryptoAction
End Class

.

Private Sub bnEcrypt_Click(sender As Object, e As EventArgs) Handles bnEcrypt.Click
        Dim bytKey As Byte()
        Dim bytIV As Byte()


        'Send the password to the CreateKey function.
        bytKey = CreateKey(txtPass.Text)
        'Send the password to the CreateIV function.
        bytIV = CreateIV(txtPass.Text)

        Dim m As New MyParameters
        m.strInputFile = txtFile.Text
        m.strOutputFile = txtPlaceIn.Text
        m.bytKey = bytKey
        m.bytIV = bytIV
        m.Direction = CryptoAction.ActionDecrypt

But I'm getting a error: Value of type '1-dimensional array of byte' cannot be converted to a byte'. on these two:

        m.bytKey = bytKey
        m.bytIV = bytIV

Any help?

Upvotes: 2

Views: 6724

Answers (3)

Jason Faulkner
Jason Faulkner

Reputation: 6608

Your class needs to accept a Byte() instead:

Class MyParameters
    Friend strInputFile As String
    Friend strOutputFile As String
    Friend bytKey As Byte() ' <-- Changed from Byte
    Friend bytIV As Byte() ' <-- Changed from Byte
    Friend Direction As New CryptoAction
End Class

Upvotes: 2

Guffa
Guffa

Reputation: 700910

You have declared two byte fields in the class. Declare two arrays instead:

Friend bytKey() As Byte
Friend bytIV() As Byte

Upvotes: 1

Patrick Hofman
Patrick Hofman

Reputation: 157136

You have your variables defined as a Byte instead of a byte array Byte().

Use this:

Friend bytKey As Byte()
Friend bytIV As Byte()

Upvotes: 2

Related Questions