We have generated RSA public key by our java program to encrypt the data in C++ before transmitting it but when we use this key to encrypt the data using Microsoft encryption API, it doesn't accepts this key.
Do anyone has any ideas on this?
We have generated RSA public key by our java program to encrypt the data in C++ before transmitting it but when we use this key to encrypt the data using Microsoft encryption API, it doesn't accepts this key.
Do anyone has any ideas on this?
Microsoft code has some intrinsic limitations on what RSA keys it can use: it requires the public key length (the modulus bit length) to be a multiple of 16, and the public exponent must fit in a 32-bit unsigned integer.
However, most RSA keys fit in those constraints and the usual suspects are encoding/decoding issues. Java tends to use big-endian everywhere, because:
On the other hand, Microsoft's CryptoAPI wants little-endian. You may have used your public modulus in the wrong order.
In my experience the serialization of an RSA key is different between Java and MS.
But, what I did was to use the Bouncy Castle API to do this, as they have a Java and .NET version of their library.
For more options you can look at this question: http://stackoverflow.com/questions/2185103/rsa-how-to-generate-private-key-in-java-and-use-it-in-c