Opc.Ua.WindowsCertificateStore.Enumerate C# (CSharp) Method

Enumerate() public method

public Enumerate ( ) : X509Certificate2Collection
return System.Security.Cryptography.X509Certificates.X509Certificate2Collection
        public X509Certificate2Collection Enumerate()
        {
            lock (m_lock)
            {   
	            X509Certificate2Collection certificates = new X509Certificate2Collection();

	            IntPtr hStore = IntPtr.Zero;
	            X509Store store = null;

	            // find the certificate.
	            try
	            {
                    // open store.
                    hStore = OpenStore(true, false, false);

		            if (hStore == IntPtr.Zero)
		            {
                        return certificates;
		            }

		            // wrap it with a managed store.
                    store = new X509Store(hStore);
                    
		            // get the certificates.
		            for (int ii = 0; ii < store.Certificates.Count; ii++)
		            {
			            certificates.Add(store.Certificates[ii]);
		            }
	            }
	            finally
	            {
		            if (store != null)
		            {
			            store.Close();
		            }

		            if (hStore != IntPtr.Zero)
                    {
                        int result = NativeMethods.CertCloseStore(hStore, 0);

                        if (result == 0)
                        {
                            Utils.Trace("Could not close certificate store. Error={0:X8}", Marshal.GetLastWin32Error());
                        }
		            }
	            }

	            return certificates;
            }
        }