我正在尝试编写一个在 RSA 中加密和解密短消息的程序,所以我一直在使用 BigInteger 对象来存储大量数字。加密工作正常,但是当我运行代码的解密部分时,它给了我一个溢出异常错误,对于使用 BigInteger.DivRem() 方法的行中的 Int32 而言,值太大或太小。这很奇怪,因为我什至没有在这段代码中使用任何 Integer 对象。谁能告诉我我在这里做错了什么?
Private Sub DecryptButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DecryptButton.Click
Dim cipherText As BigInteger
Dim cipherTextString As String
Dim n, d, counter As BigInteger
Dim f As BigInteger = 0
Dim asciiArray() As Byte = Nothing
Dim splits As String = ""
Dim decryptedText As String
counter = 0
n = BigInteger.Parse("really large number")
d = BigInteger.Parse("really large number")
BigInteger.DivRem(BigInteger.Pow(BigInteger.Parse(CipherBox.Text), d), n, f)
cipherText = f
cipherTextString = cipherText.ToString
For i As Integer = 0 To cipherTextString.Length - 1
Dim c As Char = cipherTextString(i)
If splits.Length < 2 Then
splits = splits + c.ToString
Else
asciiArray(counter) = Byte.Parse(splits)
splits = Nothing
counter = counter + 1
End If
Next
decryptedText = System.Text.ASCIIEncoding.ASCII.GetString(asciiArray)
MessageText.Text = decryptedText
End Sub