public void GetXml_SameRsa()
 {
     using (RSA rsa = RSA.Create())
     {
         RSAKeyValue rsaKeyValue1 = new RSAKeyValue(rsa);
         RSAKeyValue rsaKeyValue2 = new RSAKeyValue(rsa);
         Assert.Equal(rsaKeyValue1.GetXml(), rsaKeyValue2.GetXml());
     }
 }
Ejemplo n.º 2
0
        public void GeneratedKey()
        {
            RSAKeyValue rsa1 = new RSAKeyValue();

            Assert.IsNotNull(rsa1.Key, "Key");
            XmlElement xmlkey = rsa1.GetXml();

            RSAKeyValue rsa2 = new RSAKeyValue();

            rsa2.LoadXml(xmlkey);

            Assert.IsTrue((rsa1.GetXml().OuterXml) == (rsa2.GetXml().OuterXml), "rsa1==rsa2");

            RSA         key  = rsa1.Key;
            RSAKeyValue rsa3 = new RSAKeyValue(key);

            Assert.IsTrue((rsa3.GetXml().OuterXml) == (rsa1.GetXml().OuterXml), "rsa3==rsa1");
            Assert.IsTrue((rsa3.GetXml().OuterXml) == (rsa2.GetXml().OuterXml), "rsa3==rsa2");
        }
        public void GetXml_SameRsa()
        {
            var keyGen = GeneratorUtilities.GetKeyPairGenerator("RSA");

            keyGen.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
            var         pair         = keyGen.GenerateKeyPair();
            RSAKeyValue rsaKeyValue1 = new RSAKeyValue((RsaKeyParameters)pair.Public);
            RSAKeyValue rsaKeyValue2 = new RSAKeyValue((RsaKeyParameters)pair.Public);

            Assert.Equal(rsaKeyValue1.GetXml(), rsaKeyValue2.GetXml());
        }
        public void GetXml()
        {
            RSAKeyValue rsa    = new RSAKeyValue();
            XmlElement  xmlkey = rsa.GetXml();

            // Schema check. Should not throw.
            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();
        }
Ejemplo n.º 5
0
        public void ImportKey()
        {
            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.AreEqual(rsaKey, s, "RSA Key");
        }
        public void LoadXml_GetXml_With_NS_Prefix()
        {
            string      rsaKeyWithPrefix    = "<ds:KeyValue xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:RSAKeyValue><ds:Modulus>ogZ1/O7iks9ncETqNxLDKoPvgrT4nFx1a3lOmpywEmgbc5+8vI5dSzReH4v0YrflY75rIJx13CYWMsaHfQ78GtXvaeshHlQ3lLTuSdYEJceKll/URlBoKQtOj5qYIVSFOIVGHv4Y/0lnLftOzIydem29KKH6lJQlJawBBssR12s=</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKeyValue></ds:KeyValue>";
            string      rsaKeyWithoutPrefix = "<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(rsaKeyWithPrefix);

            RSAKeyValue rsa1 = new RSAKeyValue();

            rsa1.LoadXml(doc.DocumentElement);

            string s = rsa1.GetXml().OuterXml;

            //Comparing with rsaKeyWithoutPrefix because RSAKeyValue.GetXml().OuterXml returns the markup without the namespace prefixes
            Assert.Equal(rsaKeyWithoutPrefix, s);
        }