Example #1
0
        //
        // virtual methods
        //

        protected virtual AsymmetricAlgorithm GetPublicKey()
        {
            if (KeyInfo == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KeyInfoRequired"));
            }

            if (m_x509Enum != null)
            {
                AsymmetricAlgorithm key = GetNextCertificatePublicKey();
                if (key != null)
                {
                    return(key);
                }
            }

            if (m_keyInfoEnum == null)
            {
                m_keyInfoEnum = KeyInfo.GetEnumerator();
            }

            // In our implementation, we move to the next KeyInfo clause which is an RSAKeyValue, DSAKeyValue or KeyInfoX509Data
            while (m_keyInfoEnum.MoveNext())
            {
                RSAKeyValue rsaKeyValue = m_keyInfoEnum.Current as RSAKeyValue;
                if (rsaKeyValue != null)
                {
                    return(rsaKeyValue.Key);
                }

                DSAKeyValue dsaKeyValue = m_keyInfoEnum.Current as DSAKeyValue;
                if (dsaKeyValue != null)
                {
                    return(dsaKeyValue.Key);
                }

                KeyInfoX509Data x509Data = m_keyInfoEnum.Current as KeyInfoX509Data;
                if (x509Data != null)
                {
                    m_x509Collection = Utils.BuildBagOfCerts(x509Data, CertUsageType.Verification);
                    if (m_x509Collection.Count > 0)
                    {
                        m_x509Enum = m_x509Collection.GetEnumerator();
                        AsymmetricAlgorithm key = GetNextCertificatePublicKey();
                        if (key != null)
                        {
                            return(key);
                        }
                    }
                }

                GostKeyValue gostKeyValue = m_keyInfoEnum.Current as GostKeyValue;
                if (gostKeyValue != null)
                {
                    return(gostKeyValue.Key);
                }
            }

            return(null);
        }
Example #2
0
        protected override AsymmetricAlgorithm GetPublicKey()
        {
            if (KeyInfo == null)
            {
                throw ExceptionUtility.CryptographicException(Resources.XmlKeyInfoRequired);
            }

            if (X509Enumumerable != null)
            {
                var nextCertificatePublicKey = GetNextCertificatePublicKey();

                if (nextCertificatePublicKey != null)
                {
                    return(nextCertificatePublicKey);
                }
            }

            if (KeyInfoEnumerable == null)
            {
                KeyInfoEnumerable = KeyInfo.GetEnumerator();
            }

            var keyInfoEnum = KeyInfoEnumerable;

            while (keyInfoEnum.MoveNext())
            {
                var rsaKeyValue = keyInfoEnum.Current as RSAKeyValue;

                if (rsaKeyValue != null)
                {
                    return(rsaKeyValue.Key);
                }

                var dsaKeyValue = keyInfoEnum.Current as DSAKeyValue;

                if (dsaKeyValue != null)
                {
                    return(dsaKeyValue.Key);
                }

                var gostKeyValue = keyInfoEnum.Current as GostKeyValue;

                if (gostKeyValue != null)
                {
                    return(gostKeyValue.Key);
                }

                var keyInfoX509Data = keyInfoEnum.Current as KeyInfoX509Data;

                if (keyInfoX509Data != null)
                {
                    X509Collection = GostXmlUtils.BuildBagOfCertsVerification(keyInfoX509Data);

                    if (X509Collection.Count > 0)
                    {
                        X509Enumumerable = X509Collection.GetEnumerator();

                        var nextCertificatePublicKey = GetNextCertificatePublicKey();

                        if (nextCertificatePublicKey != null)
                        {
                            return(nextCertificatePublicKey);
                        }
                    }
                }
            }

            return(null);
        }