View Single Post
  #5  
Old 12-31-2017, 11:35
psgama psgama is offline
Friend
 
Join Date: Jul 2014
Posts: 101
Rept. Given: 0
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 12
Thanks Rcvd at 75 Times in 44 Posts
psgama Reputation: 6
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

Last edited by psgama; 12-31-2017 at 13:52.
Reply With Quote
The Following User Says Thank You to psgama For This Useful Post:
niculaita (12-31-2017)