public void GetXml()
        {
            RsaKeyValue rsa    = new RsaKeyValue();
            XmlElement  xmlkey = rsa.GetXml();


            const string schema = "http://www.w3.org/2000/09/xmldsig#";

            new[] { "Exponent", "Modulus" }
            .Select(elementName => Convert.FromBase64String(xmlkey.SelectSingleNode($"*[local-name()='RSAKeyValue' and namespace-uri()='{schema}']/*[local-name()='{elementName}' and namespace-uri()='{schema}']").InnerText))
            .ToArray();
        }
        public void LoadXml_ValidXml(string xml, byte[] expectedModulus, byte[] expectedExponent)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RsaKeyValue rsa = new RsaKeyValue();

            rsa.LoadXml(xmlDocument.DocumentElement);

            Assert.Equal(expectedModulus, rsa.GetKey().Modulus.ToByteArrayUnsigned());
            Assert.Equal(expectedExponent, rsa.GetKey().Exponent.ToByteArrayUnsigned());
        }
        public void RSAKeyValue()
        {
            var key = new RsaKeyParameters(
                isPrivate: false,
                modulus: new BigInteger(1, Convert.FromBase64String(rsaModulus)),
                exponent: new BigInteger(1, Convert.FromBase64String(rsaExponent))
                );
            RsaKeyValue rsa = new RsaKeyValue(key);

            info.AddClause(rsa);
            AssertCrypto.AssertXmlEquals("rsa",
                                         "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" +
                                         xmlRSA + "</KeyValue></KeyInfo>", (info.GetXml().OuterXml));
            Assert.Equal(1, info.Count);
        }
        public void LoadXml_LoadXml_GetXml()
        {
            string      rsaKey = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>ogZ1/O7iks9ncETqNxLDKoPvgrT4nFx1a3lOmpywEmgbc5+8vI5dSzReH4v0YrflY75rIJx13CYWMsaHfQ78GtXvaeshHlQ3lLTuSdYEJceKll/URlBoKQtOj5qYIVSFOIVGHv4Y/0lnLftOzIydem29KKH6lJQlJawBBssR12s=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue>";
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(rsaKey);

            RsaKeyValue rsa1 = new RsaKeyValue();

            rsa1.LoadXml(doc.DocumentElement);

            string s = rsa1.GetXml().OuterXml;

            Assert.Equal(rsaKey, s);
        }
        public void Complex()
        {
            KeyInfoName name = new KeyInfoName();

            name.Value = "CoreFx::";
            info.AddClause(name);

            var keyDSA = new DsaPublicKeyParameters(y: new BigInteger(Convert.FromBase64String(dsaY)),
                                                    parameters: new DsaParameters(
                                                        p: new BigInteger(1, Convert.FromBase64String(dsaP)),
                                                        q: new BigInteger(1, Convert.FromBase64String(dsaQ)),
                                                        g: new BigInteger(1, Convert.FromBase64String(dsaG))
                                                        )
                                                    );
            DsaKeyValue dsa = new DsaKeyValue(keyDSA);

            info.AddClause(dsa);

            var keyRSA = new RsaKeyParameters(
                isPrivate: false,
                modulus: new BigInteger(1, Convert.FromBase64String(rsaModulus)),
                exponent: new BigInteger(1, Convert.FromBase64String(rsaExponent))
                );
            RsaKeyValue rsa = new RsaKeyValue(keyRSA);

            info.AddClause(rsa);

            KeyInfoRetrievalMethod retrieval = new KeyInfoRetrievalMethod();

            retrieval.SetUri("https://github.com/dotnet/corefx");
            info.AddClause(retrieval);

            X509Certificate x509     = new X509CertificateParser().ReadCertificate(cert);
            KeyInfoX509Data x509data = new KeyInfoX509Data(x509);

            info.AddClause(x509data);

            string s = "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>CoreFx::</KeyName><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>rjxsMU368YOCTQejWkiuO9e/vUVwkLtq1jKiU3TtJ53hBJqjFRuTa228vZe+BH2su9RPn/vYFWfQDv6zgBYe3eNdu4Afw+Ny0FatX6dl3E77Ra6Tsd3MmLXBiGSQ1mMNd5G2XQGpbt9zsGlUaexXekeMLxIufgfZLwYp67M+2WM=</P><Q>tf0K9rMyvUrU4cIkwbCrDRhQAJk=</Q><G>S8Z+1pGCed00w6DtVcqZLKjfqlCJ7JsugEFIgSy/Vxtu9YGCMclV4ijGEbPo/jU8YOSMuD7E9M7UaopMRcmKQjoKZzoJjkgVFP48Ohxl1f08lERnButsxanx3+OstFwUGQ8XNaGg3KrIoZt1FUnfxN3RHHTvVhjzNSHxMGULGaU=</G><Y>LnrxxRGLYeV2XLtK3SYz8RQHlHFZYrtznDZyMotuRfO5uC5YODhSFyLXvb1qB3WeGtF4h3Eo4KzHgMgfN2ZMlffxFRhJgTtH3ctbL8lfQoDkjeiPPnYGhspdJxr0tyZmiy0gkjJG3vwHYrLnvZWx9Wm/unqiOlGBPNuxJ+hOeP8=</Y></DSAKeyValue></KeyValue>";

            s += "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>9DC4XNdQJwMRnz5pP2a6U51MHCODRilaIoVXqUPhCUb0lJdGroeqVYT84ZyIVrcarzD7Tqs3aEOIa3rKox0N1bxQpZPqayVQeLAkjLLtzJW/ScRJx3uEDJdgT1JnM1FH0GZTinmEdCUXdLc7+Y/c/qqIkTfbwHbRZjW0bBJyExM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue>";
            s += "<RetrievalMethod URI=\"https://github.com/dotnet/corefx\" />";
            s += "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">";
            s += "<X509Certificate>MIICHTCCAYYCARQwDQYJKoZIhvcNAQEEBQAwWDELMAkGA1UEBhMCQ0ExHzAdBgNVBAMTFktleXdpdG5lc3MgQ2FuYWRhIEluYy4xKDAmBgorBgEEASoCCwIBExhrZXl3aXRuZXNzQGtleXdpdG5lc3MuY2EwHhcNOTYwNTA3MDAwMDAwWhcNOTkwNTA3MDAwMDAwWjBYMQswCQYDVQQGEwJDQTEfMB0GA1UEAxMWS2V5d2l0bmVzcyBDYW5hZGEgSW5jLjEoMCYGCisGAQQBKgILAgETGGtleXdpdG5lc3NAa2V5d2l0bmVzcy5jYTCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAzSP6KuHtmPTp0JM+13qAAkzMwQKvXLYff/pXQm8w0SDFtSEHQCyphsLzZISuPYUu7YW9VLAYKO9q+BvnCxYfkyVPx/iOw7nKmIQOVdAv73h3xXIoX2C/GSvRcqK32D/glzRaAb0EnMh4Rc2TjRXydhARq7hbLp5S3YE+nGTIKZMCAQMwDQYJKoZIhvcNAQEEBQADgYEAMho1ur9DJ9a01Lh25eObTWzAhsl3NbprFi0TRkqwMlOhW1rpmeIMhogXTg3+gqxOR+/7/zms7jXI+lI3CkmtWa3iiqkcxl8f+G9zfs2gMegMvvVN2bKrihK2MHhoEXwN8UlNo/2y6f8d8JH6VIX/M5Dowb+km6RiRr1hElmYQYk=</X509Certificate></X509Data></KeyInfo>";
            AssertCrypto.AssertXmlEquals("Complex", s, (info.GetXml().OuterXml));
            Assert.Equal(5, info.Count);
        }
        public void LoadXml_InvalidXml(string xml)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RsaKeyValue rsa = new RsaKeyValue();



            try
            {
                rsa.LoadXml(xmlDocument.DocumentElement);
            }
            catch (System.Security.Cryptography.CryptographicException) { }
            catch (FormatException) { }
        }
        public void Ctor_Rsa_Null()
        {
            RsaKeyValue rsaKeyValue = new RsaKeyValue(null);

            Assert.Null(rsaKeyValue.GetKey());
        }
        public void Ctor_Empty()
        {
            RsaKeyValue rsaKeyValue = new RsaKeyValue();

            Assert.NotNull(rsaKeyValue.GetKey());
        }
        public void LoadXml_Null()
        {
            RsaKeyValue rsa = new RsaKeyValue();

            Assert.Throws <ArgumentNullException>(() => rsa.LoadXml(null));
        }