コード例 #1
0
        protected virtual AsymmetricKeyParameter GetPublicKey()
        {
            if (KeyInfo == null)
            {
                throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_KeyInfoRequired);
            }

            if (_x509Enum != null)
            {
                AsymmetricKeyParameter key = GetNextCertificatePublicKey();
                if (key != null)
                {
                    return(key);
                }
            }

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

            while (_keyInfoEnum.MoveNext())
            {
                RsaKeyValue rsaKeyValue = _keyInfoEnum.Current as RsaKeyValue;
                if (rsaKeyValue != null)
                {
                    return(rsaKeyValue.GetKey());
                }

                DsaKeyValue dsaKeyValue = _keyInfoEnum.Current as DsaKeyValue;
                if (dsaKeyValue != null)
                {
                    return(dsaKeyValue.GetKey());
                }

                KeyInfoX509Data x509Data = _keyInfoEnum.Current as KeyInfoX509Data;
                if (x509Data != null)
                {
                    _x509Collection = CryptoUtils.BuildBagOfCerts(x509Data, CertUsageType.Verification);
                    if (_x509Collection.Count > 0)
                    {
                        _x509Enum = _x509Collection.GetEnumerator();
                        AsymmetricKeyParameter key = GetNextCertificatePublicKey();
                        if (key != null)
                        {
                            return(key);
                        }
                    }
                }
            }

            return(null);
        }