类型' 1维字节数组的值'无法转换为字节

时间:2014-12-19 16:22:31

标签: .net vb.net

我试图将值传递给后台工作者。我之前发帖询问如何完成here。答案指示我使用此代码,但我在尝试使用它时遇到问题。这就是我正在做的事情:

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

但是我收到错误:类型的值'字节的一维数组'无法转换为字节' 。关于这两个:

        m.bytKey = bytKey
        m.bytIV = bytIV

任何帮助?

3 个答案:

答案 0 :(得分:2)

您的班级需要接受Byte()

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

答案 1 :(得分:1)

您将变量定义为Byte而不是字节数组Byte()

使用此:

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

答案 2 :(得分:1)

您已在类中声明了两个字节字段。改为声明两个数组:

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