简体   繁体   中英

How to validate public key xml file?

I have created a public key using RSACryptoServiceProvider in c#. Later in my program I want to store it's content in database. How can I make sure that the file is a true public key.

Note: I have checked it's structure against xsd. but I need more. Any help?

the code to produce public key:

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
string publicKey = rsa.ToXmlString(false);

finally I've found a solution: first I check the schema against a xsd file, and then

                try
                {
                    var csp = new RSACryptoServiceProvider();
                    var reader = new StreamReader(address);
                    var xml = reader.ReadToEnd();
                    csp.FromXmlString(xml);
                }
                catch
                {
                    //not a rsa public key                   
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM