Anyone know how to correctly convert the base64 encoded P and Q values back to a proper integer?
I am trying to use the systems.numerics biginteger format and the output isn't looking correct. My Byte Arrays are coming back correctly from my RSAGetP function, as if I convert the array back to base64 format it matches the original RSA XML
Code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim PBytes() As Byte = RSAGetP(txtPrivateKey.Text)
Dim PValue As New BigInteger(PBytes)
Dim QBytes() As Byte = RSAGetQ(txtPrivateKey.Text)
Dim QValue As New BigInteger(QBytes)
Dim MBytes() As Byte = RSAGetM(txtPrivateKey.Text)
Dim MValue As New BigInteger(MBytes)
TextBox1.Text = PValue.ToString
TextBox2.Text = QValue.ToString
TextBox3.Text = MValue.ToString
End Sub
Solved the issue with the following function. The Byte Order is backwards to what Biginteger wants
Code:
Function PrepareRSA(Bytes() As Byte)
Array.Reverse(Bytes)
If (Bytes((Bytes.Length - 1)) > 127) Then
Array.Resize(Bytes, (Bytes.Length + 1))
Bytes((Bytes.Length - 1)) = 0
End If
Return Bytes
End Function