-1

I am supplied the following RSA private key in the format

<RSAKeyValue>
   <Modulus>XXXXXXXX</Modulus>
   <Exponent>XXXXXXXX</Exponent>
   <P>XXXXXXXX</P>
   <Q>XXXXXXXX</Q>
   <DP>XXXXXXXX</DP>
   <DQ>XXXXXXXX</DQ>
   <InverseQ>XXXXXXXXXX/InverseQ>
   <D>XXXXXXXX</D>
</RSAKeyValue>

The XXXX are in Base64 format.

I want to know how to combine it all the XXXXXX bits to a single Base64 string.
With this single Base64 string i do the following:
1. Feed it to a TMemorStream
2. use Indy's TIdDecoderMIME class to decode Base64 from the MemoryStream
3. The decoded MemoryStream is then feed into CryptDecrypt function from wcrypt2.pas (a delphi wrapper of Microsoft's Cryptographic API) from Jedi

I know the solution for public key in the same format

<RSAKeyValue>
<Modulus>xqiYKv0umaLdmrKPyBfYmAfzZYVsvsOJyS4c1lBPjqpn7zh+XyxPXK7MxJkAlenQJM33M+ZYfmlPLya7JWXXTPviylEEtlmul9GshpX2caxWu2YO9vNIHRZYYau4ccbkm95iMyJi8KN2ANtqDwiJv55vcXZDqjPSDE4ap49xmog==</Modulus>
<Exponent>AAQC</Exponent>
</RSAKeyValue>

The solution is to add "BgIAAACkAABSU0ExAAQAAAE" + Exponent + Modulus

The result is: BgIAAACkAABSU0ExAAQAAAEAAQCxqiYKv0umaLdmrKPyBfYmAfzZYVsvsOJyS4c1lBPjqpn7zh+XyxPXK7MxJkAlenQJM33M+ZYfmlPLya7JWXXTPviylEEtlmul9GshpX2caxWu2YO9vNIHRZYYau4ccbkm95iMyJi8KN2ANtqDwiJv55vcXZDqjPSDE4ap49xmog==

With the private key how do we combine it? I know it starts off like this:

"BwIAAACkAABSU0ExAAQAAAE" + Exponent + Modulus + ???????

  • Which bit are you stuck on? – David Heffernan Sep 06 '13 at 09:51
  • I want to combine all the XXXX in the RSAKeyValue to a single Base64 like this: BwIAAACkAABSU0EyAAQAAAEAAQBv6tBGUnT2KUcP4eHoxrsUNWOfB70LTX5UnImACuItbD6glLmvAx6ygDqvqSw691iWo5oMpH1QU6W40Dqpo....... – user2732388 Sep 06 '13 at 10:05
  • I know the first part, like you add "BwIAAACkAABSU0ExAAQAAAE" + exponent + modulus. But i dont know how to add the rest. – user2732388 Sep 06 '13 at 10:09
  • If you are using Indy, encode it to base 64 with the tools provided by that library – David Heffernan Sep 06 '13 at 10:13
  • Sorry, i think i am not making what i want clear. I do not have any issuing encoding bytes or strings to base64. The XXXX in the RSAKeyValue XML are in base64, just that i do not want to expose the details there. I want to know how do i combine all the XXXX base64 codes into a single base64 private key – user2732388 Sep 06 '13 at 10:22
  • Another clue, is that if i just add them all it will be 4 characters more than the private key i get with CryptGenKey – user2732388 Sep 06 '13 at 10:29

1 Answers1

1

The XXXX in the RSAKeyValue XML are in base64, just that i do not want to expose the details there. I want to know how do i combine all the XXXX base64 codes into a single base64 private key.

I suspect that this means that you are performing the base64 encoding line by line. It's much simpler to perform the encoding on the entire file.

For example you might do this as follows:

  1. Load the file into a TStringList.
  2. Extract a single string representing the file using the Text property of the string list.
  3. Base64 encode that string.
  4. Send it over the wire.
  5. At the receiving end, decode the string.
  6. Assign the string to the Text property of a string list.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490