Ejemplo n.º 1
0
        // Reconstruct an asymmetric algorithm object from an XML string.
        public override void FromXmlString(String xmlString)
        {
            SecurityElement elem;
            DSAParameters   dsaParams = new DSAParameters();
            String          tag;

            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            try
            {
                elem = SecurityElement.Parse(xmlString);
                if (elem == null || elem.Tag != "DSAKeyValue")
                {
                    throw new CryptographicException
                              (_("Crypto_InvalidDSAParams"));
                }
                foreach (SecurityElement child in elem.Children)
                {
                    tag = child.Tag;
                    if (tag == "P")
                    {
                        dsaParams.P = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "Q")
                    {
                        dsaParams.Q = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "G")
                    {
                        dsaParams.G = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "Y")
                    {
                        dsaParams.Y = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "J")
                    {
                        dsaParams.J = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "Seed")
                    {
                        dsaParams.Seed = Convert.FromBase64String
                                             (child.Text);
                    }
                    else if (tag == "X")
                    {
                        dsaParams.X = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "PgenCounter")
                    {
                        byte[] count = Convert.FromBase64String
                                           (child.Text);
                        dsaParams.Counter = 0;
                        foreach (byte b in count)
                        {
                            dsaParams.Counter =
                                (dsaParams.Counter << 8) + (int)b;
                        }
                    }
                }
            }
            catch (FormatException)
            {
                throw new CryptographicException
                          (_("Crypto_InvalidDSAParams"));
            }
            catch (ArgumentNullException)
            {
                throw new CryptographicException
                          (_("Crypto_InvalidDSAParams"));
            }
            ImportParameters(dsaParams);
        }
Ejemplo n.º 2
0
Archivo: RSA.cs Proyecto: ForNeVeR/pnet
        // Reconstruct an asymmetric algorithm object from an XML string.
        public override void FromXmlString(String xmlString)
        {
            SecurityElement elem;
            RSAParameters   rsaParams = new RSAParameters();
            String          tag;

            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            try
            {
                elem = SecurityElement.Parse(xmlString);
                if (elem == null || elem.Tag != "RSAKeyValue")
                {
                    throw new CryptographicException
                              (_("Crypto_InvalidRSAParams"));
                }
                foreach (SecurityElement child in elem.Children)
                {
                    tag = child.Tag;
                    if (tag == "Modulus")
                    {
                        rsaParams.Modulus = Convert.FromBase64String
                                                (child.Text);
                    }
                    else if (tag == "Exponent")
                    {
                        rsaParams.Exponent = Convert.FromBase64String
                                                 (child.Text);
                    }
                    else if (tag == "D")
                    {
                        rsaParams.D = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "DP")
                    {
                        rsaParams.DP = Convert.FromBase64String
                                           (child.Text);
                    }
                    else if (tag == "DQ")
                    {
                        rsaParams.DQ = Convert.FromBase64String
                                           (child.Text);
                    }
                    else if (tag == "InverseQ")
                    {
                        rsaParams.InverseQ = Convert.FromBase64String
                                                 (child.Text);
                    }
                    else if (tag == "P")
                    {
                        rsaParams.P = Convert.FromBase64String
                                          (child.Text);
                    }
                    else if (tag == "Q")
                    {
                        rsaParams.Q = Convert.FromBase64String
                                          (child.Text);
                    }
                }
            }
            catch (FormatException)
            {
                throw new CryptographicException
                          (_("Crypto_InvalidRSAParams"));
            }
            catch (ArgumentNullException)
            {
                throw new CryptographicException
                          (_("Crypto_InvalidRSAParams"));
            }
            ImportParameters(rsaParams);
        }