views:

487

answers:

2

I've created a public/private key using RSACryptoServiceProvider and saved it as XML. I can use this to encrypt/decrypt/sign and verify data in .NET.

I have another application which is intended to run on a Linux server. I'm developing it in C++ and I'm using Crypto++ for my cryptography needs.

I want to share data between these two applications, but to do that I need to convert the RSAParameters into public/private keys that Crypto++ can understand.

I'm also open to using convert public/private keys generated by Crypto++ into RSAParameters if it is easier to do.

Any ideas?

A: 

Can the source provided in the article be modified to interop with RSA cryptography routines between .NET & Crypto++?

Christo
+1  A: 

The easiest way is probably to use the RSAParameters directly instead of going over XML.

Just store the byte-arrays contained in the RSAParameters in a file using a format of your own choice. Read the byte-arrays back in your C++ program and create CryptoPP::Integers from them. Use those Integers to Initialize a RSAFunction (public key) or InvertibleRSAFunction (private key).

The reverse way is similiar: I.e.

RSAFunction publicKey = ...;

size_t modulusLength = publicKey.getModulus().ByteCount();
unsigned char * modulus = new unsigned char[modulusLength];
publicKey.getModulus().Encode(modulus, modulusLength);

// similarly with PublicExponent and remember to clean up the arrays.

and transfer the arrays to your .NET-application, where you can use them to initialize an RSAParameters.

Rasmus Faber
I knew it would be trivially simple for somebody... Just got it working yesterday by packing the private key in the PKCS #8 format and the public key in the X509 format. I think your way would have been easier.
Christo