Saving an RSA key pair to a file


I’m having trouble finding a good/complete VB.Net Chilkat example of how to generate an RSA key container with a key pair (private and public) and save that key container to a file.


I think I can clarify.  With 2 points:

1) In actuality, an RSA private key also contains the public-part of the key.  It contains the all of the key parts:  modulus, exponent, D, P, Q, DP, DQ, and InverseQ.  The public key is really just a sub-set of the private key and is composed of the modulus and exponent.  Therefore, to save the key pair, you really only need to save the private key.

2) The “key container” in a file would be an encrypted or unencrypted PEM (text) or DER (binary) file.  Either can be PCKS8 format or “RSA” format.  You would use the Chilkat.PrivateKey file to save the private key to PEM or DER (see the reference docs).  You may export the private key from the Chilkat.Rsa class to an XML string, and then load it into the Chilkat.PrivateKey class, and then save it to a file in whichever format you desire, using encryption or not.