Exemple #1
0
        unsafe private static SafeCertificateStoreHandle OpenSystemStoreWrapper(StoreName storeName)
        {
            uint flags = (uint)StoreOpenFlags.CERT_STORE_NO_CRYPT_RELEASE_FLAG;

            if (storeName == StoreName.SPC)
            {
                flags |= (uint)SystemStoreLocation.CERT_SYSTEM_STORE_LOCAL_MACHINE;
            }
            else
                flags |= (uint)SystemStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER;

            fixed(char *name = storeName.ToString())
            {
                SafeCertificateStoreHandle store = Direct.CertOpenStore(
                    lpszStoreProvider: (IntPtr)StoreProvider.CERT_STORE_PROV_SYSTEM,
                    dwMsgAndCertEncodingType: 0,
                    hCryptProv: IntPtr.Zero,
                    dwFlags: flags,
                    pvPara: (IntPtr)name);

                return(store);
            }
        }