Ejemplo n.º 1
0
        /// <summary>Reconstructs a <see cref="T:System.Security.Cryptography.DSA" /> object from an XML string.</summary>
        /// <param name="xmlString">The XML string to use to reconstruct the <see cref="T:System.Security.Cryptography.DSA" /> object. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="xmlString" /> parameter is <see langword="null" />. </exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">The format of the <paramref name="xmlString" /> parameter is not valid. </exception>
        // Token: 0x06002178 RID: 8568 RVA: 0x0007658C File Offset: 0x0007478C
        public override void FromXmlString(string xmlString)
        {
            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            DSAParameters   parameters = default(DSAParameters);
            Parser          parser     = new Parser(xmlString);
            SecurityElement topElement = parser.GetTopElement();
            string          text       = topElement.SearchForTextOfLocalName("P");

            if (text == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "DSA",
                    "P"
                }));
            }
            parameters.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text));
            string text2 = topElement.SearchForTextOfLocalName("Q");

            if (text2 == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "DSA",
                    "Q"
                }));
            }
            parameters.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text2));
            string text3 = topElement.SearchForTextOfLocalName("G");

            if (text3 == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "DSA",
                    "G"
                }));
            }
            parameters.G = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text3));
            string text4 = topElement.SearchForTextOfLocalName("Y");

            if (text4 == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "DSA",
                    "Y"
                }));
            }
            parameters.Y = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text4));
            string text5 = topElement.SearchForTextOfLocalName("J");

            if (text5 != null)
            {
                parameters.J = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text5));
            }
            string text6 = topElement.SearchForTextOfLocalName("X");

            if (text6 != null)
            {
                parameters.X = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text6));
            }
            string text7 = topElement.SearchForTextOfLocalName("Seed");
            string text8 = topElement.SearchForTextOfLocalName("PgenCounter");

            if (text7 != null && text8 != null)
            {
                parameters.Seed    = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text7));
                parameters.Counter = Utils.ConvertByteArrayToInt(Convert.FromBase64String(Utils.DiscardWhiteSpaces(text8)));
            }
            else if (text7 != null || text8 != null)
            {
                if (text7 == null)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                    {
                        "DSA",
                        "Seed"
                    }));
                }
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "DSA",
                    "PgenCounter"
                }));
            }
            this.ImportParameters(parameters);
        }
Ejemplo n.º 2
0
        // We can provide a default implementation of FromXmlString because we require
        // every DSA implementation to implement ImportParameters
        // All we have to do here is parse the XML.

        public override void FromXmlString(String xmlString)
        {
            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            Contract.EndContractBlock();
            DSAParameters   dsaParams  = new DSAParameters();
            Parser          p          = new Parser(xmlString);
            SecurityElement topElement = p.GetTopElement();

            // P is always present
            String pString = topElement.SearchForTextOfLocalName("P");

            if (pString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "P"));
            }
            dsaParams.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(pString));

            // Q is always present
            String qString = topElement.SearchForTextOfLocalName("Q");

            if (qString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "Q"));
            }
            dsaParams.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(qString));

            // G is always present
            String gString = topElement.SearchForTextOfLocalName("G");

            if (gString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "G"));
            }
            dsaParams.G = Convert.FromBase64String(Utils.DiscardWhiteSpaces(gString));

            // Y is always present
            String yString = topElement.SearchForTextOfLocalName("Y");

            if (yString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "Y"));
            }
            dsaParams.Y = Convert.FromBase64String(Utils.DiscardWhiteSpaces(yString));

            // J is optional
            String jString = topElement.SearchForTextOfLocalName("J");

            if (jString != null)
            {
                dsaParams.J = Convert.FromBase64String(Utils.DiscardWhiteSpaces(jString));
            }

            // X is optional -- private key if present
            String xString = topElement.SearchForTextOfLocalName("X");

            if (xString != null)
            {
                dsaParams.X = Convert.FromBase64String(Utils.DiscardWhiteSpaces(xString));
            }

            // Seed and PgenCounter are optional as a unit -- both present or both absent
            String seedString        = topElement.SearchForTextOfLocalName("Seed");
            String pgenCounterString = topElement.SearchForTextOfLocalName("PgenCounter");

            if ((seedString != null) && (pgenCounterString != null))
            {
                dsaParams.Seed    = Convert.FromBase64String(Utils.DiscardWhiteSpaces(seedString));
                dsaParams.Counter = Utils.ConvertByteArrayToInt(Convert.FromBase64String(Utils.DiscardWhiteSpaces(pgenCounterString)));
            }
            else if ((seedString != null) || (pgenCounterString != null))
            {
                if (seedString == null)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "Seed"));
                }
                else
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "DSA", "PgenCounter"));
                }
            }

            ImportParameters(dsaParams);
        }
Ejemplo n.º 3
0
        // Import/export functions

        // We can provide a default implementation of FromXmlString because we require
        // every RSA implementation to implement ImportParameters
        // All we have to do here is parse the XML.

        public override void FromXmlString(String xmlString)
        {
            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            Contract.EndContractBlock();
            RSAParameters   rsaParams  = new RSAParameters();
            Parser          p          = new Parser(xmlString);
            SecurityElement topElement = p.GetTopElement();

            // Modulus is always present
            String modulusString = topElement.SearchForTextOfLocalName("Modulus");

            if (modulusString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "RSA", "Modulus"));
            }
            rsaParams.Modulus = Convert.FromBase64String(Utils.DiscardWhiteSpaces(modulusString));

            // Exponent is always present
            String exponentString = topElement.SearchForTextOfLocalName("Exponent");

            if (exponentString == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", "RSA", "Exponent"));
            }
            rsaParams.Exponent = Convert.FromBase64String(Utils.DiscardWhiteSpaces(exponentString));

            // P is optional
            String pString = topElement.SearchForTextOfLocalName("P");

            if (pString != null)
            {
                rsaParams.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(pString));
            }

            // Q is optional
            String qString = topElement.SearchForTextOfLocalName("Q");

            if (qString != null)
            {
                rsaParams.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(qString));
            }

            // DP is optional
            String dpString = topElement.SearchForTextOfLocalName("DP");

            if (dpString != null)
            {
                rsaParams.DP = Convert.FromBase64String(Utils.DiscardWhiteSpaces(dpString));
            }

            // DQ is optional
            String dqString = topElement.SearchForTextOfLocalName("DQ");

            if (dqString != null)
            {
                rsaParams.DQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(dqString));
            }

            // InverseQ is optional
            String inverseQString = topElement.SearchForTextOfLocalName("InverseQ");

            if (inverseQString != null)
            {
                rsaParams.InverseQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(inverseQString));
            }

            // D is optional
            String dString = topElement.SearchForTextOfLocalName("D");

            if (dString != null)
            {
                rsaParams.D = Convert.FromBase64String(Utils.DiscardWhiteSpaces(dString));
            }

            ImportParameters(rsaParams);
        }
Ejemplo n.º 4
0
        /// <summary>Initializes an <see cref="T:System.Security.Cryptography.RSA" /> object from the key information from an XML string.</summary>
        /// <param name="xmlString">The XML string containing <see cref="T:System.Security.Cryptography.RSA" /> key information. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="xmlString" /> parameter is <see langword="null" />. </exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">The format of the <paramref name="xmlString" /> parameter is not valid. </exception>
        // Token: 0x06002293 RID: 8851 RVA: 0x0007C3A4 File Offset: 0x0007A5A4
        public override void FromXmlString(string xmlString)
        {
            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            RSAParameters   parameters = default(RSAParameters);
            Parser          parser     = new Parser(xmlString);
            SecurityElement topElement = parser.GetTopElement();
            string          text       = topElement.SearchForTextOfLocalName("Modulus");

            if (text == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "RSA",
                    "Modulus"
                }));
            }
            parameters.Modulus = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text));
            string text2 = topElement.SearchForTextOfLocalName("Exponent");

            if (text2 == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[]
                {
                    "RSA",
                    "Exponent"
                }));
            }
            parameters.Exponent = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text2));
            string text3 = topElement.SearchForTextOfLocalName("P");

            if (text3 != null)
            {
                parameters.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text3));
            }
            string text4 = topElement.SearchForTextOfLocalName("Q");

            if (text4 != null)
            {
                parameters.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text4));
            }
            string text5 = topElement.SearchForTextOfLocalName("DP");

            if (text5 != null)
            {
                parameters.DP = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text5));
            }
            string text6 = topElement.SearchForTextOfLocalName("DQ");

            if (text6 != null)
            {
                parameters.DQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text6));
            }
            string text7 = topElement.SearchForTextOfLocalName("InverseQ");

            if (text7 != null)
            {
                parameters.InverseQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text7));
            }
            string text8 = topElement.SearchForTextOfLocalName("D");

            if (text8 != null)
            {
                parameters.D = Convert.FromBase64String(Utils.DiscardWhiteSpaces(text8));
            }
            this.ImportParameters(parameters);
        }