Example #1
0
        public virtual void LoadFromXmlString(string xmlString)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlString);

            if (xmlDoc.DocumentElement.Name.Equals(RsaKeyTagType.KeyPair))
            {
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                {
                    if (node.Name == RsaKeyTagType.Public)
                    {
                        PublicKey = new RsaPublicKey();
                        PublicKey.LoadFromXmlString(node.OuterXml);
                    }
                    else if (node.Name == RsaKeyTagType.Private)
                    {
                        PrivateKey = new RsaPrivateKey();
                        PrivateKey.LoadFromXmlString(node.OuterXml);
                    }
                    else if (node.Name == RsaKeyTagType.KeyLength)
                    {
                        KeyLength = Int32.Parse(node.InnerText);
                    }
                }
            }
            else
            {
                throw new Exception("Invalid XML RSA key.");
            }
        }
Example #2
0
 public RsaKeyPair(int keyLength)
 {
     KeyLength = keyLength;
     using (var rsa = System.Security.Cryptography.RSA.Create())
     {
         rsa.KeySize = keyLength;
         PublicKey   = new RsaPublicKey(rsa.ExportParameters(false), keyLength);
         PrivateKey  = new RsaPrivateKey(rsa.ExportParameters(true), keyLength);
     }
 }