-2
 Public Shared Function EncryptRSA(ByVal infilename As String, ByVal outfilename As String, ByVal pubkey As String) As String
        Dim buffer2 As Byte()
        Dim buffer3 As Byte()
        Dim provider As New RSACryptoServiceProvider
        provider.FromXmlString(File.ReadAllText(pubkey))
        Dim sourceArray As Byte() = File.ReadAllBytes(infilename)
        Dim num As Integer = (sourceArray.Length / &H3A)
        Dim stream As FileStream = File.Create(outfilename)
        Dim num2 As Integer = 0

        For num2 = 0 To num - 1
            buffer2 = New Byte(&H3A - 1) {}
            Array.Copy(sourceArray, (num2 * &H3A), buffer2, 0, &H3A)
            buffer3 = provider.Encrypt(buffer2, True)
            stream.Write(buffer3, 0, buffer3.Length)
        Next num2
        If ((sourceArray.Length Mod &H3A) <> 0) Then
            buffer2 = New Byte((sourceArray.Length Mod &H3A) - 1) {}

            Array.Copy(sourceArray, ((sourceArray.Length / &H3A) * &H3A), buffer2, 0, (sourceArray.Length Mod &H3A))
            buffer3 = provider.Encrypt(buffer2, True)
            stream.Write(buffer3, 0, buffer3.Length)
        End If
        stream.Close()
        Return File.ReadAllText(outfilename)
    End Function

错误 1 ​​重载解析失败,因为没有缩小转换就无法调用可访问的“副本”:“公共共享子副本(sourceArray As System.Array,sourceIndex As Long,destinationArray As System.Array,destinationIndex As Long,length As Long)” :参数匹配参数“sourceIndex”从“Double”缩小到“Long”。'公共共享子副本(sourceArray As System.Array,sourceIndex As Integer,destinationArray As System.Array,destinationIndex As Integer,length As Integer)':参数匹配参数 'sourceIndex' 从 'Double' 缩小到 'Integer'。C:\Users\user\AppData\Local\Temporary Projects\WindowsApplication1\Crypto.vb 52 13 WindowsApplication1

4

1 回答 1

0

你有这一行:

Array.Copy(sourceArray, ((sourceArray.Length / &H3A) * &H3A), buffer2, 0, (sourceArray.Length Mod &H3A)) 

编译器想要告诉您的是,您为 sourceIndex 提供了一个 double 值,但它期望一个 long 值。double 不能隐式转换为 long,因为 long 不能表示 double 的所有可能值。

明确地进行转换:

Array.Copy(sourceArray, CLng((sourceArray.Length / &H3A) * &H3A), buffer2, 0, (sourceArray.Length Mod &H3A)) 
于 2012-04-18T20:14:19.493 回答