Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

c# RSA extract public key from private key

Is there a way to extract public key from private key in c#? Becouse if i do ToXMLString() then i can set if i want public key information saved with the private key. So now im thinking that is there a way to extract public key from private?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...