Вот еще одна попытка, где я пытаюсь сделать это с некоторыми изменениями в основной функции.
Private Sub TestBTN_Click(sender As Object, e As EventArgs) Handles TestBTN.Click
Dim MyRSACryptoServiceProvider As New RSACryptoServiceProvider(384)
Dim MyRSAParams As RSAParameters
Dim P As BigInteger
Dim Q As BigInteger
Dim Modulus As BigInteger
Dim Modulus1 As BigInteger
Dim Exponent As BigInteger
Dim D As BigInteger
Dim DP As BigInteger
Dim DQ As BigInteger
Dim InverseQ As BigInteger
Dim PrimeList, PrimeList2 As New List(Of BigInteger)
Dim x As Integer = 1
Dim RandomNumber1, RandomNumber2 As Integer
Dim Random As New Random
Using StreamReader As New StreamReader("G:\PrimeList384P1.txt")
Dim line As String
While x <= 1000
line = StreamReader.ReadLine
If x >= 501 And x <= 1000 Then
PrimeList2.Add(BigInteger.Parse(line))
Else
PrimeList.Add(BigInteger.Parse(line))
End If
x += 1
End While
End Using
RandomNumber1 = Random.Next(0, (PrimeList.Count - 1))
RandomNumber2 = RandomNumber1
Q = PrimeList(RandomNumber1)
P = PrimeList2(RandomNumber2)
Modulus = (P - 1) * (Q - 1)
D = ModInverse(65537, Modulus)
x = 0
If BigInteger.GreatestCommonDivisor(P, Q) = 1 And BigInteger.GreatestCommonDivisor(Modulus, 65537) = 1 And BigInteger.GreatestCommonDivisor(D, Modulus) = 1 Then
Else
While x < 500
Q = PrimeList(x)
P = PrimeList2(x)
Modulus = (P - 1) * (Q - 1)
D = ModInverse(65537, Modulus)
If BigInteger.GreatestCommonDivisor(P, Q) = 1 And BigInteger.GreatestCommonDivisor(Modulus, 65537) = 1 And BigInteger.GreatestCommonDivisor(D, Modulus) = 1 Then
Exit While
End If
x += 1
End While
End If
Exponent = 65537
ExponentTextBox.Text = Exponent.ToString
DTextBox.Text = D.ToString
PTextBox.Text = P.ToString
QTextBox.Text = Q.ToString
ModulusTextBox.Text = Modulus.ToString
DP = BigInteger.Remainder(D, (P - 1))
DQ = BigInteger.Remainder(D, (Q - 1))
InverseQ = ModInverse(Q, P)
DPTextBox.Text = DP.ToString
DQTextBox.Text = DQ.ToString
InverseQTextBox.Text = InverseQ.ToString
MyRSAParams.P = ExportUnsignedBigEndian(P)
MyRSAParams.Q = ExportUnsignedBigEndian(Q)
MyRSAParams.Modulus = ExportUnsignedBigEndian(Modulus)
MyRSAParams.Exponent = ExportUnsignedBigEndian(Exponent)
MyRSAParams.D = ExportUnsignedBigEndian(D)
MyRSAParams.DP = ExportUnsignedBigEndian(DP)
MyRSAParams.DQ = ExportUnsignedBigEndian(DQ)
MyRSAParams.InverseQ = ExportUnsignedBigEndian(InverseQ)
MyRSACryptoServiceProvider.ImportParameters(MyRSAParams)
End Sub
System.Security.Cryptography.CryptographicException HResult = 0x80090005
Сообщение = неверные данные .
Source = mscorlib StackTrace:
в System.Security.Cryptography.CryptographicException.ThrowCryptographicException (Int32 ч.)
в System.Security.Cryptography.Utils._ImportHle (Безопасный ключ) hCSP, Int32 keyNumber, CspProviderFlags флаги, объект cspObject, SafeKeyHandle & hKey)
в System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (параметры RSAParameters)
TB объекта (RST) EventArgs e) в C: \ Users \ chew \ source \ repos \ RSATesting \ Form1.vb: строка 109
в System. Windows .Forms.Control.OnClick (EventArgs e) в System. Windows .Forms.Button.OnClick (EventArgs e)
в System. Windows .Forms.Button.OnMouseUp (MouseEventArgs mevent) в System. Windows .Forms.Control.WmMouseUp ( Сообщение & m, кнопка MouseButtons, щелчки Int32)
в системе. Windows .Forms.Control.WndPro c (Сообщение & m) в системе. Windows .Forms.ButtonBase.WndPro c ( Сообщение & m)
в Системе. Windows .Forms.Button.WndPro c (Сообщение & m) в Системе. Windows .Forms.Control.ControlNativeWindow.OnMessage (Сообщение & m)
в System. Windows .Forms.Control.ControlNativeWindow.WndPro c (Message & m) в System. Windows .Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
в System. Windows .Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg) в
System. Windows .Forms.Application.ComponentManager.System. Windows .Forms.UnsafeNativeMethods.MsoCom .FPushMessageL oop (IntPtr dwComponentID, причина Int32, Int32
pvLoopData) в системе. Windows .Forms.Application.ThreadContext.RunMessageLoopInner (причина Int32,
контекст ApplicationContext) в системе . Windows .Forms.Application.ThreadContext.RunMessageL oop (Int 32 причины,
контекст ApplicationContext) в Microsoft.VisualBasi c .ApplicationServices.WindowsFormsApplicationBase.OnRun () в
Microsoft.VisualBasi c .ApplicationServices.WindowsFormsApplicationBasel.AApplicationBase. atApp .VisualBasi c .ApplicationServices.WindowsFormsApplicationBase.Run (String [] commandLine)
в RSATesting.My.MyApplication.Main (String [] Args) в строке 81