Ejemplo n.º 1
0
        public void LoadXml_InvalidXml(string xml)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RSAKeyValue rsa = new RSAKeyValue();

            Assert.Throws <CryptographicException>(() => rsa.LoadXml(xmlDocument.DocumentElement));
        }
Ejemplo n.º 2
0
        public void InvalidValue2()
        {
            string      badKey = "<Test></Test>";
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(badKey);

            RSAKeyValue rsa = new RSAKeyValue();

            rsa.LoadXml(doc.DocumentElement);
        }
        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.Key.Modulus.ToByteArrayUnsigned());
            Assert.Equal(expectedExponent, rsa.Key.Exponent.ToByteArrayUnsigned());
        }
Ejemplo n.º 4
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_ValidXml(string xml, byte[] expectedModulus, byte[] expectedExponent)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RSAKeyValue rsa = new RSAKeyValue();

            rsa.LoadXml(xmlDocument.DocumentElement);

            RSAParameters rsaParameters = rsa.Key.ExportParameters(false);

            Assert.Equal(expectedModulus, rsaParameters.Modulus);
            Assert.Equal(expectedExponent, rsaParameters.Exponent);
        }
        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);
        }
        public void LoadXml_InvalidXml(string xml)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RSAKeyValue rsa = new RSAKeyValue();

            // FormatException exception because desktop does not
            // check if Convert.FromBase64String throws
            // Related to: https://github.com/dotnet/corefx/issues/18690
            try
            {
                rsa.LoadXml(xmlDocument.DocumentElement);
            }
            catch (System.Security.Cryptography.CryptographicException) { }
            catch (FormatException) { }
        }
Ejemplo n.º 8
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 LoadXml_InvalidXml(string xml)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);

            RSAKeyValue rsa = new RSAKeyValue();

            // FormatException exception because .NET Framework does not
            // check if Convert.FromBase64String throws
            // Related to: https://github.com/dotnet/runtime/issues/21236
            try
            {
                rsa.LoadXml(xmlDocument.DocumentElement);
            }
            catch (CryptographicException) { }
            catch (FormatException) when(PlatformDetection.IsNetFramework)
            {
            }
        }
Ejemplo n.º 10
0
        public void InvalidValue1()
        {
            RSAKeyValue rsa = new RSAKeyValue();

            rsa.LoadXml(null);
        }
        public void LoadXml_Null()
        {
            RSAKeyValue rsa = new RSAKeyValue();

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