How to generate xml based RSA keys ( private ,public ) which should be compatible for .NET environment. I tried phpseclib module in PHP. But it is not compatible for .NET. Please suggest me any way to generate the xml based RSA keys in Java ? Actually I am working on linux based system. Using these keys I am going to perform encryption and decryption operation.
Like
<RSAKeyValue>
<Modulus>4hjg1ibWXHIlH...ssmlBfMAListzrgk=</Modulus>
<Exponent>AQAB</Exponent>
<P>8QZCtrmJcr9uW7VRex+diH...jLHV5StmuBs1+vZZAQ==</P>
<Q>8CUvJTv...yeDszMWNCQ==</Q>
<DP>elh2Nv...cygE3657AQ==</DP>
<DQ>MBUh5XC...+PfiMfX0EQ==</DQ>
<InverseQ>oxvsj4WCbQ....LyjggXg==</InverseQ>
<D>KrhmqzAVasx...uxQ5VGZmZ6yOAE=</D>
</RSAKeyValue>
There’s no support for this out of the box in Java, but it’s still fairly trivial. First off, you generate an RSA key pair using the JCA
KeyPairGenerator.Then, you need to cast the private key to the appropriate interface (we use
RSAPrivateCrtKeyinstead ofRSAPrivateKeyso we can access the CRT parts), and using Apache Commons Codec for Base64 encoding.You can use a proper XML API if you’re so inclined, but I felt no compelling reason not to use
StringBuilderin this case. Also, feel free to inline theBigIntegerinstances. I declared them as variables to make the mapping between Java methods and XML elements more obvious.