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重载解析失败,因为无法访问&#39;复制&#39;可以在没有缩小转换的情况下调用: &#39; Public Shared Sub Copy(sourceArray As System.Array,sourceIndex As Long,destinationArray As System.Array,destinationIndex As Long,length As Long)&#39 ;: Argument matching parameter&#39; sourceIndex&#39;来自&#39; Double&#39;长期&#39; &#39;公共共享子拷贝(sourceArray As System.Array,sourceIndex As Integer,destinationArray As System.Array,destinationIndex As Integer,length as Integer)&#39 ;:参数匹配参数&#39; sourceIndex&#39;来自&#39; Double&#39;到整数&#39;。 C:\ Users \ user \ AppData \ Local \ Temporary Projects \ WindowsApplication1 \ Crypto.vb 52 13 WindowsApplication1
答案 0 :(得分: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))