Beispiel #1
0
        public void ToCapiPublicKeyBlob_DSA()
        {
            DSA dsa = DSA.Create();

            // full keypair
            dsa.FromXmlString(dsaKeyPairString);
            byte[] pubkey = CryptoConvert.ToCapiPublicKeyBlob(dsa);
            Assert.AreEqual(BitConverter.ToString(dsaPubBlob), BitConverter.ToString(pubkey), "PublicKey-1");

            // public key only
            dsa.FromXmlString(dsaPubKeyString);
            pubkey = CryptoConvert.ToCapiPublicKeyBlob(dsa);
            Assert.AreEqual(BitConverter.ToString(dsaPubBlob), BitConverter.ToString(pubkey), "PublicKey-2");
        }
Beispiel #2
0
        public static void FromNonsenseXml()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-512 test case, with the G value from the DSA-1024 case.
                try
                {
                    dsa.FromXmlString(
                        @"
<DSAKeyValue xmlns:yep=""urn:ignored:yep"" xmlns:nope=""urn:ignored:nope"" xmlns:ign=""urn:ignored:ign"">
  <yep:P>1qi38cr3ppZNB2Y/xpHSL2q81Vw3rvWNIHRnQNgv4U4UY2NifZGSUULc3uOEvgoeBO1b9fRxSG9NmG1CoufflQ==</yep:P>
  <nope:Q>+rX2JdXV4WQwoe9jDr4ziXzCJPk=</nope:Q>
  <G>
    a8NmtmNVVF4Jjx/pDlRptWfgn6edgX8rNntF3s1DAaWcgdaRH3aR03DhWsaSwEvB
    GHLBcaf+ZU6WPX3aV1qemM4Cb7fTk0olhggTSo7F7WmirtyJQBtnrd5Cfxftrrct
    evRdmrHVnhsT1O + 9F8dkMwJn3eNSwg4FuA2zwQn + i5w =
  </G>
  <ign:Y>wwDg5n2HfmztOf7qqsHywr1WjmoyRnIn4Stq5FqNlHhUGkgKyAA4qshjgn1uOYQGGiWQXBi9JJmoOWY8PKRWBQ==</ign:Y>
</DSAKeyValue>");
                }
                catch (ArgumentException)
                {
                    // DSACng, DSAOpenSsl
                }
                catch (CryptographicException)
                {
                    // DSACryptoServiceProvider
                }
            }
        }
Beispiel #3
0
        public void ToXmlStringWithoutSeed()
        {
            DSA d = DSA.Create();

            d.FromXmlString("<DSAKeyValue><P>vb95327o8+f5lbrS9qSXxLQYTkcP/WTlJnI0fuw/vFaf7DFQe/ORdTqpa0I3okDOcRiUihzr0y58aQarlNf58MMhMcx/XqRzB2UOVZ/bt2EpfAC3CISwXHlHFoW6+dCHpc72aJOXpreWV6k0oZUg71tKMsPVUP1I8xgELArxAUE=</P><Q>5ul/yRjQ8hFv4w94ZHsP337ebjk=</Q><G>NunCU4DkWaq6IKKhRPCMBBmMgILU8Zqd3aHe0UyKZLYFSOjcKkOIPJ9iWtfDtErHcxb3yjHRV6/EndR+wX8rNsTjYDeUGg5vC6IV4Es+rRCmhVXQ7Y2N+bAH71VxPRbNC90NjgYqKwXZHf2l6c+W4XRvRvNiM5puwz+ubWcm5AA=</G><Y>hQinH+upZPNtTS2o7bi03EOybn9eHC8U61/Rax+oe00YPG+0Md7Okup6CMxZmww0n2F8W7YRZeI7Pltm8TlpmUdMmGSAiILUX585vFM19GR4XeSecqpj1BFO/x4T9tGeakoWxquEjFl4JqEuvDQwnvM76jWDmkUTI4U8kJPnHcw=</Y><J>0l0NjQKpwTJt+h8qmlXhbt4jL+OnaSZkM1zdyIPmOpNavJz7slGtoDAneoQ8STNiT+RrNqGdPbs5glAP8sXS0mdKJ6dGQuySGwGZTP9cWCq81YjRJJ74QuPJUYUruuhN0RTkiukqGzkJYQtA</J></DSAKeyValue>");
            d.ToXmlString(false);
        }
Beispiel #4
0
        public static void FromXmlInvalidJ_Fails()
        {
            // No one really reads the J value on import, but xmldsig defined it,
            // so we read it and pass it to ImportParameters.
            // That means it has to be legal base64.

            // This key comes from FIPS-186-2, Appendix 5, Example of the DSA.
            // The version in DSATestData does not have the seed or counter supplied.

            using (DSA dsa = DSAFactory.Create())
            {
                Assert.Throws <FormatException>(
                    () => dsa.FromXmlString(@"
<DSAKeyValue>
  <P>
    jfKklEkidqo9JXWbsGhpy+rA2Dr7jQz3y7gyTw14guXQdi/FtyEOr8Lprawyq3qs
    SWk9+/g3JMLsBzbuMcgCkQ==
  </P>
  <Q>x3MhjHN+yO6ZO08t7TD0jtrOkV8=</Q>
  <G>
    Ym0CeDnqChNBMWOlW0y1ACmdVSKVbO/LO/8Q85nOLC5xy53l+iS6v1jlt5Uhklyc
    xC6fb0ZLCIzFcq9T5teIAg==
  </G>
  <Y>
    GRMYcddbFhKoGfKdeNGw1zRveqd7tiqFm/1sVnXanSEtOjbvFnLvZguMfCVcwOx0
    hY+6M/RMBmmWMKdrAw7jMw==
  </Y>
  <J>AgRO2deYCHK5/u5+ElWfz2J6fdI2PN/mnjBxceE11r5zt7x/DVqcoWAp2+d</J>
  <Seed>1QFOS2DvK6i2IRtAYroyJOBCfdM=</Seed>
  <PgenCounter>aQ==</PgenCounter>
  <X>IHCzIj26Ny/eHA/8ey47SYsmBhQ=</X>
</DSAKeyValue>"));
            }
        }
Beispiel #5
0
        public static void FromXmlCounterWithoutSeed()
        {
            // This key comes from FIPS-186-2, Appendix 5, Example of the DSA.
            // The version in DSATestData does not have the seed or counter supplied.

            using (DSA dsa = DSAFactory.Create())
            {
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(@"
<DSAKeyValue>
  <P>
    jfKklEkidqo9JXWbsGhpy+rA2Dr7jQz3y7gyTw14guXQdi/FtyEOr8Lprawyq3qs
    SWk9+/g3JMLsBzbuMcgCkQ==
  </P>
  <Q>x3MhjHN+yO6ZO08t7TD0jtrOkV8=</Q>
  <G>
    Ym0CeDnqChNBMWOlW0y1ACmdVSKVbO/LO/8Q85nOLC5xy53l+iS6v1jlt5Uhklyc
    xC6fb0ZLCIzFcq9T5teIAg==
  </G>
  <Y>
    GRMYcddbFhKoGfKdeNGw1zRveqd7tiqFm/1sVnXanSEtOjbvFnLvZguMfCVcwOx0
    hY+6M/RMBmmWMKdrAw7jMw==
  </Y>
  <J>AgRO2deYCHK5/u5+ElWfz2J6fdI2PN/mnjBxceE11r5zt7x/DVqcoWAp2+dr</J>
  <PgenCounter>aQ==</PgenCounter>
  <X>IHCzIj26Ny/eHA/8ey47SYsmBhQ=</X>
</DSAKeyValue>"));
            }
        }
Beispiel #6
0
        public void ToCapiPrivateKeyBlob_PublicKeyOnly_DSA()
        {
            DSA dsa = DSA.Create();

            dsa.FromXmlString(dsaPubKeyString);
            byte[] pubkey = CryptoConvert.ToCapiPrivateKeyBlob(dsa);
        }
        /// <summary>Constructor</summary>
        /// <param name="xmlKey">string</param>
        /// <param name="eaa">EnumDigitalSignAlgorithm</param>
        public DigitalSignXML(string xmlKey, EnumDigitalSignAlgorithm eaa)
        {
            AsymmetricAlgorithm aa = null;
            HashAlgorithm       ha = null;

            AsymmetricAlgorithmCmnFunc.CreateDigitalSignSP(eaa, out aa, out ha);

            this.AsymmetricAlgorithm = aa;
            this.HashAlgorithm       = ha;

            if (aa is RSA)
            {
                RSA rsa = (RSA)aa;
                rsa.FromXmlString(xmlKey);
                this.AsymmetricAlgorithm = rsa;
            }
            else if (aa is DSA)
            {
                DSA dsa = (DSA)aa;
                dsa.FromXmlString(xmlKey);
                this.AsymmetricAlgorithm = dsa;
            }
            else
            {
                throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
            }
        }
Beispiel #8
0
        public static void FromToXml()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                DSAParameters pubOnly = dsa.ExportParameters(false);
                DSAParameters pubPriv = dsa.ExportParameters(true);

                string xmlPub  = dsa.ToXmlString(false);
                string xmlPriv = dsa.ToXmlString(true);

                using (DSA dsaPub = DSAFactory.Create())
                {
                    dsaPub.FromXmlString(xmlPub);

                    DSAImportExport.AssertKeyEquals(pubOnly, dsaPub.ExportParameters(false));
                }

                using (DSA dsaPriv = DSAFactory.Create())
                {
                    dsaPriv.FromXmlString(xmlPriv);

                    DSAImportExport.AssertKeyEquals(pubPriv, dsaPriv.ExportParameters(true));
                    DSAImportExport.AssertKeyEquals(pubOnly, dsaPriv.ExportParameters(false));
                }
            }
        }
Beispiel #9
0
        public static void FromXmlWithSeedAndCounterAndJ()
        {
            // This key comes from FIPS-186-2, Appendix 5, Example of the DSA.
            // The version in DSATestData does not have the seed or counter supplied.

            using (DSA dsa = DSAFactory.Create())
            {
                dsa.FromXmlString(@"
<DSAKeyValue>
  <P>
    jfKklEkidqo9JXWbsGhpy+rA2Dr7jQz3y7gyTw14guXQdi/FtyEOr8Lprawyq3qs
    SWk9+/g3JMLsBzbuMcgCkQ==
  </P>
  <Q>x3MhjHN+yO6ZO08t7TD0jtrOkV8=</Q>
  <G>
    Ym0CeDnqChNBMWOlW0y1ACmdVSKVbO/LO/8Q85nOLC5xy53l+iS6v1jlt5Uhklyc
    xC6fb0ZLCIzFcq9T5teIAg==
  </G>
  <Y>
    GRMYcddbFhKoGfKdeNGw1zRveqd7tiqFm/1sVnXanSEtOjbvFnLvZguMfCVcwOx0
    hY+6M/RMBmmWMKdrAw7jMw==
  </Y>
  <J>AgRO2deYCHK5/u5+ElWfz2J6fdI2PN/mnjBxceE11r5zt7x/DVqcoWAp2+dr</J>
  <Seed>1QFOS2DvK6i2IRtAYroyJOBCfdM=</Seed>
  <PgenCounter>aQ==</PgenCounter>
  <X>IHCzIj26Ny/eHA/8ey47SYsmBhQ=</X>
</DSAKeyValue>");

                DSATestData.GetDSA1024_186_2(out DSAParameters expected, out _, out _);
                DSAImportExport.AssertKeyEquals(expected, dsa.ExportParameters(true));
            }
        }
Beispiel #10
0
        public void DSAImportPrivateExportPrivate()
        {
            DSAParameters input = AllTests.GetKey(true);

            dsa.ImportParameters(input);
            string xmlDSA = dsa.ToXmlString(true);

            dsa.FromXmlString(xmlDSA);
            Assert.AreEqual(xmlPrivate, xmlDSA, "DSA Import Private Export Private (xml)");
            DSAParameters output = dsa.ExportParameters(true);

            AssertEquals("DSA Import Private Export Private (binary)", AllTests.GetKey(true), output, true);
        }
Beispiel #11
0
 /// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.DSAKeyValue" /> state from an XML element.</summary>
 /// <param name="value">The XML element to load the <see cref="T:System.Security.Cryptography.Xml.DSAKeyValue" /> state from. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception>
 /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <paramref name="value" /> parameter is not a valid <see cref="T:System.Security.Cryptography.Xml.DSAKeyValue" /> XML element. </exception>
 public override void LoadXml(XmlElement value)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     m_key.FromXmlString(value.OuterXml);
 }
Beispiel #12
0
 public static void TestPlatformNotSupportedException()
 {
     using (DSA dsa = DSAFactory.Create())
     {
         Assert.Throws <PlatformNotSupportedException>(() => dsa.FromXmlString(null));
         Assert.Throws <PlatformNotSupportedException>(() => dsa.ToXmlString(true));
     }
 }
Beispiel #13
0
        public void ToXmlStringWithZeroCounter()
        {
            DSA d = DSA.Create();

            // <PgenCounter>AA==</PgenCounter> == 0
            d.FromXmlString("<DSAKeyValue><P>s/Oc0t4gj0NRqkCKi4ynJnOAEukNhjkHJPOzNsHP69kyHMUwZ3AzOkLGYOWlOo2zlYKzSbZygDDI5dCWA5gQF2ZGHEUlWJMgUyHmkybOi44cyHaX9yeGfbnoc3xF9sYgkA3vPUZaJuYMOsBp3pyPdeN8/mLU8n0ivURyP+3Ge9M=</P><Q>qkcTW+Ce0L5k8OGTUMkRoGKDc1E=</Q><G>PU/MeGp6I/FBduuwD9UPeCFzg8Ib9H5osku5nT8AhHTY8zGqetuvHhxbESt4lLz8aXzX0oIiMsusBr6E/aBdooBI36fHwW8WndCmwkB1kv7mhRIB4302UrfvC2KWQuBypfl0++a1whBMCh5VTJYH1sBkFIaVNeUbt5Q6/UdiZVY=</G><Y>shJRUdGxEYxSKM5JVol9HAdQwIK+wF9X4n9SAD++vfZOMOYi+M1yuvQAlQvnSlTTWr7CZPRVAICLgDBbqi9iN+Id60ccJ+hw3pGDfLpJ7IdFPszJEeUO+SZBwf8njGXULqSODs/NTciiX7E07rm+KflxFOg0qtWAhmYLxIkDx7s=</Y><J>AAAAAQ6LSuRiYdsocZ6rgyqIOpE1/uCO1PfEn758Lg2VW6OHJTYHNC30s0gSTG/Jt3oHYX+S8vrtNYb8kRJ/ipgcofGq2Qo/cYKP7RX2K6EJwSfWInhsNMr1JmzuK0lUKkXXXVo15fL8O2/16uEWMg==</J><Seed>uYM5b20luvbuyevi9TXHwekbr5s=</Seed><PgenCounter>AA==</PgenCounter><X>fAOytZttUZFzt/AvwRinmvYKL7E=</X></DSAKeyValue>");
            d.ToXmlString(false);
        }
Beispiel #14
0
        public void ToCapiPrivateKeyBlob_DSA()
        {
            DSA dsa = DSA.Create();

            dsa.FromXmlString(dsaKeyPairString);
            byte[] keypair = CryptoConvert.ToCapiPrivateKeyBlob(dsa);
            AssertEquals("KeyPair", dsaPrivBlob, keypair);
        }
Beispiel #15
0
 public static void FromNullXml()
 {
     using (DSA dsa = DSAFactory.Create())
     {
         AssertExtensions.Throws <ArgumentNullException>(
             "xmlString",
             () => dsa.FromXmlString(null));
     }
 }
Beispiel #16
0
        public static bool DeDSA(this string data, string privatekey, string originalData)
        {
            //Byte[] result;
            DSA dsa = DSA.Create();

            dsa.FromXmlString(privatekey);
            SHA1 sha1 = System.Security.Cryptography.SHA1.Create();

            return(dsa.VerifySignature(sha1.ComputeHash(Convert.FromBase64String(originalData)), Convert.FromBase64String(data)));
        }
Beispiel #17
0
        public override void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            // Get the XML string
            m_key.FromXmlString(value.OuterXml);
        }
Beispiel #18
0
        public void ToCapiKeyBlob_DSA()
        {
            DSA dsa = DSA.Create();

            dsa.FromXmlString(dsaKeyPairString);
            byte[] keypair = CryptoConvert.ToCapiKeyBlob(dsa, true);
            AssertEquals("KeyPair", dsaPrivBlob, keypair);

            byte[] pubkey = CryptoConvert.ToCapiKeyBlob(dsa, false);
            Assert.AreEqual(BitConverter.ToString(dsaPubBlob), BitConverter.ToString(pubkey), "PublicKey");
        }
Beispiel #19
0
        public static string EnDSA(this string data, string publickey)
        {
            DSA dsa = DSA.Create();

            Byte[] result;
            dsa.FromXmlString(publickey);
            SHA1 sha1 = System.Security.Cryptography.SHA1.Create();

            result = dsa.CreateSignature(sha1.ComputeHash(Convert.FromBase64String(data)));
            return(Convert.ToBase64String(result));
        }
Beispiel #20
0
        public void DSAKeyValue()
        {
            DSA key = DSA.Create();

            key.FromXmlString(xmlDSA);
            DSAKeyValue dsa = new DSAKeyValue(key);

            info.AddClause(dsa);
            AssertCrypto.AssertXmlEquals("dsa", "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + xmlDSA + "</KeyValue></KeyInfo>", (info.GetXml().OuterXml));
            Assert.AreEqual(1, info.Count, "dsa count");
        }
Beispiel #21
0
        public override void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || (value.NamespaceURI != XmlSignature.NamespaceURI))
            {
                throw new CryptographicException("value");
            }

            dsa.FromXmlString(value.InnerXml);
        }
Beispiel #22
0
        public static void FromXmlWrongCounter_SometimesOK()
        {
            // DSACryptoServiceProvider doesn't check this error state, DSACng does.
            //
            // So, either the import gets rejected (because the counter value should be 105,
            // but says 106) and throws a CryptographicException derivitive, or it succeeds,
            // and exports the correct key material.

            // This key comes from FIPS-186-2, Appendix 5, Example of the DSA.
            // The version in DSATestData does not have the seed or counter supplied.

            using (DSA dsa = DSAFactory.Create())
            {
                bool checkKey = true;

                try
                {
                    dsa.FromXmlString(@"
<DSAKeyValue>
  <P>
    jfKklEkidqo9JXWbsGhpy+rA2Dr7jQz3y7gyTw14guXQdi/FtyEOr8Lprawyq3qs
    SWk9+/g3JMLsBzbuMcgCkQ==
  </P>
  <Q>x3MhjHN+yO6ZO08t7TD0jtrOkV8=</Q>
  <G>
    Ym0CeDnqChNBMWOlW0y1ACmdVSKVbO/LO/8Q85nOLC5xy53l+iS6v1jlt5Uhklyc
    xC6fb0ZLCIzFcq9T5teIAg==
  </G>
  <Y>
    GRMYcddbFhKoGfKdeNGw1zRveqd7tiqFm/1sVnXanSEtOjbvFnLvZguMfCVcwOx0
    hY+6M/RMBmmWMKdrAw7jMw==
  </Y>
  <J>AgRO2deYCHK5/u5+ElWfz2J6fdI2PN/mnjBxceE11r5zt7x/DVqcoWAp2+dr</J>
  <Seed>1QFOS2DvK6i2IRtAYroyJOBCfdM=</Seed>
  <PgenCounter>ag==</PgenCounter>
  <X>IHCzIj26Ny/eHA/8ey47SYsmBhQ=</X>
</DSAKeyValue>");
                }
                catch (CryptographicException)
                {
                    checkKey = false;
                }

                if (checkKey)
                {
                    DSATestData.GetDSA1024_186_2(out DSAParameters expected, out _, out _);
                    DSAImportExport.AssertKeyEquals(expected, dsa.ExportParameters(true));
                }
            }
        }
Beispiel #23
0
        public static void FromInvalidXml()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-512 test case, with an unfinished closing element.
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(
                        @"
<DSAKeyValue xmlns:yep=""urn:ignored:yep"" xmlns:nope=""urn:ignored:nope"" xmlns:ign=""urn:ignored:ign"">
  <yep:P>1qi38cr3ppZNB2Y/xpHSL2q81Vw3rvWNIHRnQNgv4U4UY2NifZGSUULc3uOEvgoeBO1b9fRxSG9NmG1CoufflQ==</yep:P>
  <nope:Q>+rX2JdXV4WQwoe9jDr4ziXzCJPk=</nope:Q>
  <G>CETEkOUu9Y4FkCxjbWTR1essYIKg1PO/0c4Hjoe0On73u+zhmk7+Km2cIp02AIPOqfch85sFuvlwUt78Z6WKKw==</G>
  <ign:Y>wwDg5n2HfmztOf7qqsHywr1WjmoyRnIn4Stq5FqNlHhUGkgKyAA4qshjgn1uOYQGGiWQXBi9JJmoOWY8PKRWBQ==</ign:Y>
</DSA"));
            }
        }
Beispiel #24
0
        public static void FromXml_MissingQ()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-576 test case, but with an element missing.
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(
                        @"
<DSAKeyValue>
  <Y>wwDg5n2HfmztOf7qqsHywr1WjmoyRnIn4Stq5FqNlHhUGkgKyAA4qshjgn1uOYQGGiWQXBi9JJmoOWY8PKRWBQ==</Y>
  <BananaWeight unit=""lbs"">30000</BananaWeight>
  <X>Lj16hMhbZnheH2/nlpgrIrDLmLw=</X>
  <G>CETEkOUu9Y4FkCxjbWTR1essYIKg1PO/0c4Hjoe0On73u+zhmk7+Km2cIp02AIPOqfch85sFuvlwUt78Z6WKKw==</G>
  <P>1qi38cr3ppZNB2Y/xpHSL2q81Vw3rvWNIHRnQNgv4U4UY2NifZGSUULc3uOEvgoeBO1b9fRxSG9NmG1CoufflQ==</P>
</DSAKeyValue>"));
            }
        }
Beispiel #25
0
        public static void FromXml_MissingG()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-576 test case, but with an element missing.
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(
                        @"
<DSAKeyValue>
  <Y>wwDg5n2HfmztOf7qqsHywr1WjmoyRnIn4Stq5FqNlHhUGkgKyAA4qshjgn1uOYQGGiWQXBi9JJmoOWY8PKRWBQ==</Y>
  <Q>+rX2JdXV4WQwoe9jDr4ziXzCJPk=</Q>
  <BananaWeight unit=""lbs"">30000</BananaWeight>
  <X>Lj16hMhbZnheH2/nlpgrIrDLmLw=</X>
  <P>1qi38cr3ppZNB2Y/xpHSL2q81Vw3rvWNIHRnQNgv4U4UY2NifZGSUULc3uOEvgoeBO1b9fRxSG9NmG1CoufflQ==</P>
</DSAKeyValue>"));
            }
        }
Beispiel #26
0
        public static void FromXml_MissingY()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-576 test case, but with an element missing.
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(
                        @"
<DSAKeyValue>
  <Q>+rX2JdXV4WQwoe9jDr4ziXzCJPk=</Q>
  <BananaWeight unit=""lbs"">30000</BananaWeight>
  <X>Lj16hMhbZnheH2/nlpgrIrDLmLw=</X>
  <G>CETEkOUu9Y4FkCxjbWTR1essYIKg1PO/0c4Hjoe0On73u+zhmk7+Km2cIp02AIPOqfch85sFuvlwUt78Z6WKKw==</G>
  <P>1qi38cr3ppZNB2Y/xpHSL2q81Vw3rvWNIHRnQNgv4U4UY2NifZGSUULc3uOEvgoeBO1b9fRxSG9NmG1CoufflQ==</P>
</DSAKeyValue>"));
            }
        }
Beispiel #27
0
        public static void FromXml_MissingP()
        {
            using (DSA dsa = DSAFactory.Create())
            {
                // This is the DSA-576 test case, but with an element missing.
                Assert.Throws <CryptographicException>(
                    () => dsa.FromXmlString(
                        @"
<DSAKeyValue>
  <Y>wwDg5n2HfmztOf7qqsHywr1WjmoyRnIn4Stq5FqNlHhUGkgKyAA4qshjgn1uOYQGGiWQXBi9JJmoOWY8PKRWBQ==</Y>
  <Q>+rX2JdXV4WQwoe9jDr4ziXzCJPk=</Q>
  <BananaWeight unit=""lbs"">30000</BananaWeight>
  <X>Lj16hMhbZnheH2/nlpgrIrDLmLw=</X>
  <G>CETEkOUu9Y4FkCxjbWTR1essYIKg1PO/0c4Hjoe0On73u+zhmk7+Km2cIp02AIPOqfch85sFuvlwUt78Z6WKKw==</G>
</DSAKeyValue>"));
            }
        }
Beispiel #28
0
        public void Complex()
        {
            KeyInfoName name = new KeyInfoName();

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

            DSA keyDSA = DSA.Create();

            keyDSA.FromXmlString(xmlDSA);
            DSAKeyValue dsa = new DSAKeyValue(keyDSA);

            info.AddClause(dsa);

            RSA keyRSA = RSA.Create();

            keyRSA.FromXmlString(xmlRSA);
            RSAKeyValue rsa = new RSAKeyValue(keyRSA);

            info.AddClause(rsa);

            KeyInfoRetrievalMethod retrieval = new KeyInfoRetrievalMethod();

            retrieval.Uri = "http://www.go-mono.org/";
            info.AddClause(retrieval);

            X509Certificate x509     = new X509Certificate(cert);
            KeyInfoX509Data x509data = new KeyInfoX509Data(x509);

            info.AddClause(x509data);

            string s = "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>Mono::</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><J>9RhE5TycDtdEIXxS3HfxFyXYgpy81zY5lVjwD6E9JP37MWEi80BlX6ab1YPm6xYSEoqReMPP9RgGiW6DuACpgI7+8vgCr4i/7VhzModJAA56PwvTu6UMt9xxKU/fT672v8ucREkMWoc7lEey</J><Seed>HxW3N4RHWVgqDQKuGg7iJTUTiCs=</Seed><PgenCounter>Asw=</PgenCounter></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>";
#if NET_1_0
            s += "<RetrievalElement URI=\"http://www.go-mono.org/\" />";
#else
            s += "<RetrievalMethod URI=\"http://www.go-mono.org/\" />";
#endif
            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.AreEqual(5, info.Count, "RetrievalMethod count");
        }
Beispiel #29
0
        protected bool REad(XmlDocument doc)
        {
            SignedXml signedXml = new SignedXml(doc);

            XmlNodeList nodeList = doc.GetElementsByTagName("Signature");

            // Load the signature node.
            signedXml.LoadXml((XmlElement)nodeList[0]);
            XmlElement xmlElement = doc.DocumentElement;
            DSA        ke         = DSA.Create();

            foreach (XmlNode xnode in xmlElement)
            {
                if (xnode.Name == "KEy")
                {
                    ke.FromXmlString(xnode.InnerText);
                    break;
                }
            }

            return(signedXml.CheckSignature(ke));
        }
Beispiel #30
0
        /// <include file='doc\KeyInfo.uex' path='docs/doc[@for="DSAKeyValue.LoadXml"]/*' />
        public override void LoadXml(XmlElement value)
        {
            // Guard against nulls
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);

            nsm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
            XmlNodeList dsaKeyValueNodes = value.SelectNodes("ds:DSAKeyValue", nsm);

            if (dsaKeyValueNodes.Count == 0)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "KeyValue");
            }
            // Get the XML string
            String dsaKeyValueString = value.OuterXml;

            // import the params
            m_key.FromXmlString(dsaKeyValueString);
        }