The normal private key format for RSA includes the public key (the "public exponent" is useful for implementation of private key operations in a way which resists timing attacks). Therefore, it is possible to extract the public key from the private key.
(It is theoretically possible to have a "pure RSA private key" which does NOT include the public exponent, but it has drawbacks, such as much harder protection against side-channel attacks, and reduced performance. Therefore nobody in their right mind does that. You can assume that when you have the private key you actually have the complete key pair.)
In the C#/.NET standard library, public and private RSA keys can be represented as XML strings (ToXmlString()
and FromXmlString()
) or a custom RSAParameters
structure (ExportParameters()
and ImportParameters()
). If you can obtain the complete private key then you just have to pick the public fields (modulus and public exponent), which constitute together the public key. Note that RSACryptoServiceProvider
may be an interface to an underlying RSA implementation which could refuse to export the private key (but will usually accept to export the public key).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…