Internal.Cryptography.Pal.OpenSslPkcs12Reader.ReadCertificates C# (CSharp) Method

ReadCertificates() public method

public ReadCertificates ( ) : List
return List
        public List<OpenSslX509CertificateReader> ReadCertificates()
        {
            var certs = new List<OpenSslX509CertificateReader>();

            if (_caStackHandle != null && !_caStackHandle.IsInvalid)
            {
                int caCertCount = Interop.Crypto.GetX509StackFieldCount(_caStackHandle);

                for (int i = 0; i < caCertCount; i++)
                {
                    IntPtr certPtr = Interop.Crypto.GetX509StackField(_caStackHandle, i);

                    if (certPtr != IntPtr.Zero)
                    {
                        // The STACK_OF(X509) still needs to be cleaned up, so upref the handle out of it.
                        certs.Add(new OpenSslX509CertificateReader(Interop.Crypto.X509UpRef(certPtr)));
                    }
                }
            }

            if (_x509Handle != null && !_x509Handle.IsInvalid)
            {
                // The certificate and (if applicable) private key handles will be given over
                // to the OpenSslX509CertificateReader, and the fields here are thus nulled out to
                // prevent double-Dispose.
                OpenSslX509CertificateReader reader = new OpenSslX509CertificateReader(_x509Handle);
                _x509Handle = null;

                if (_evpPkeyHandle != null && !_evpPkeyHandle.IsInvalid)
                {
                    reader.SetPrivateKey(_evpPkeyHandle);
                    _evpPkeyHandle = null;
                }

                certs.Add(reader);
            }

            return certs;
        }

Usage Example

Example #1
0
        private static IStorePal PfxToCollection(OpenSslPkcs12Reader pfx, string password)
        {
            pfx.Decrypt(password);

            X509Certificate2Collection coll = new X509Certificate2Collection();

            foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
            {
                coll.Add(new X509Certificate2(certPal));
            }

            return(new OpenSslX509StoreProvider(coll));
        }
All Usage Examples Of Internal.Cryptography.Pal.OpenSslPkcs12Reader::ReadCertificates