Esempio n. 1
0
        public void GetXml()
        {
            DSAKeyValue dsa    = new DSAKeyValue();
            XmlElement  xmlkey = dsa.GetXml();

            XmlNamespaceManager ns = new XmlNamespaceManager(xmlkey.OwnerDocument.NameTable);

            ns.AddNamespace("schema", SignedXml.XmlDsigNamespaceUrl);

            IEnumerable <XmlNode> elements =
                new[] { "P", "Q", "G", "Y", "J", "Seed", "PgenCounter" }
            .Select(elementName => xmlkey.SelectSingleNode($"/schema:DSAKeyValue/schema:{elementName}", ns))
            .Where(element => element != null);

            //There MUST be existing elements
            Assert.NotEmpty(elements);

            //Existing elements MUST include a "Y"-Element
            Assert.True(elements.SingleOrDefault(element => element.Name == "Y") != null);

            //Existing elements MUST contain InnerText
            Assert.True(elements.All(element => !string.IsNullOrEmpty(element.InnerText)));

            //Existing elements MUST be convertible from BASE64
            elements.Select(element => Convert.FromBase64String(element.InnerText));
        }
Esempio n. 2
0
        public void GetXml_SameDsa()
        {
            var         pair         = TestHelpers.DSAGenerateKeyPair();
            DSAKeyValue dsaKeyValue1 = new DSAKeyValue((DsaPublicKeyParameters)pair.Public);
            DSAKeyValue dsaKeyValue2 = new DSAKeyValue((DsaPublicKeyParameters)pair.Public);

            Assert.Equal(dsaKeyValue1.GetXml(), dsaKeyValue2.GetXml());
        }
Esempio n. 3
0
 public void GetXml_SameDsa()
 {
     using (DSA dsa = DSA.Create())
     {
         DSAKeyValue dsaKeyValue1 = new DSAKeyValue(dsa);
         DSAKeyValue dsaKeyValue2 = new DSAKeyValue(dsa);
         Assert.Equal(dsaKeyValue1.GetXml(), dsaKeyValue2.GetXml());
     }
 }
Esempio n. 4
0
 public void GetXml_SameDsa()
 {
     using (DSA dsa = TestHelpers.GetWorkingDSA())
     {
         DSAKeyValue dsaKeyValue1 = new DSAKeyValue(dsa);
         DSAKeyValue dsaKeyValue2 = new DSAKeyValue(dsa);
         Assert.Equal(dsaKeyValue1.GetXml(), dsaKeyValue2.GetXml());
     }
 }
Esempio n. 5
0
        public void GenerateKey()
        {
            DSAKeyValue dsa1 = new DSAKeyValue();

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

            DSAKeyValue dsa2 = new DSAKeyValue();

            dsa2.LoadXml(xmlkey);

            Assert.IsTrue((dsa1.GetXml().OuterXml) == (dsa2.GetXml().OuterXml), "dsa1==dsa2");

            DSA         key  = dsa1.Key;
            DSAKeyValue dsa3 = new DSAKeyValue(key);

            Assert.IsTrue((dsa3.GetXml().OuterXml) == (dsa1.GetXml().OuterXml), "dsa3==dsa1");
            Assert.IsTrue((dsa3.GetXml().OuterXml) == (dsa2.GetXml().OuterXml), "dsa3==dsa2");
        }
Esempio n. 6
0
        public void ImportKey()
        {
            string      dsaKey = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>xc+QZRWTgr390gzwNXF+WzoepZkvAQvCzfCm+YyXj0KPoeHHeSc5ORzXQw81V+7XJR3gupvlI4F7lW9YC538l+3eqGm8IQlCIS+U+7ICTDOFFKevqsYX0BnjO0vvE4aAtDyxfSOTCOAo1cJ+6G6xgcC1JGIBEYCtg1tH8wUewDE=</P><Q>yyfZb0S/rimXl9ScJ3zIba2oGl8=</Q><G>crLazMg+vgI7u6+Idgi9iTLdRa4fptat3gdY97zcc857+OVdmT+lVRpK3okWpmBbw2wSffU8QltwFf42BVs+/HGUOUo2hNqSSXgzl1i+1frO7/cqooHVcy5WX0xxaIPsKcREPI5pNPj/3g8apTgErLMGsHkFdngwbMed9DArTks=</G><Y>FlAozo17wV/LCMRrtnmMKxVQNpidJVkZNM1/0eR65x8giwPs6yXzJmFT8f2tmPJY2FIOAtp5JYin4xUhwIHF452Gg50wUrjV6WTGkiC+gzLC2fVIyGlVsFecLj6ue7J+MACG+b3NQnxFuT5maQnPnEeuGgjLXfwYsAR1vfU0Gas=</Y><J>+UPMvUPq9Fo6Q1fr2oEYDxfGMMtfdoQmVBxI+TkUYQsReodRzBbnvGV1uPLWTpKKd/uJNUHO/QGb05Cvc6u49/AToDJIyi4e01hTLNCzeQk/Hj19gowb5wkTIjyaH04VyPE5zYoTYfuu3Y3Q</J><Seed>+cvoO7bzdpAwAjnDDApPzBCl6zg=</Seed><PgenCounter>ATM=</PgenCounter></DSAKeyValue></KeyValue>";
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(dsaKey);

            DSAKeyValue dsa1 = new DSAKeyValue();

            dsa1.LoadXml(doc.DocumentElement);

            string s = (dsa1.GetXml().OuterXml);

            Assert.AreEqual(dsaKey, s, "DSA Key");
        }