Beispiel #1
0
        internal static NCryptProviderName[] EnumerateStorageProviders()
        {
            uint             providerCount  = 0;
            SafeNCryptBuffer providerBuffer = null;

            try
            {
                // Ask CNG for the raw list of providers
                ErrorCode enumStatus = UnsafeNativeMethods.NCryptEnumStorageProviders(out providerCount,
                                                                                      out providerBuffer,
                                                                                      0);

                if (enumStatus != ErrorCode.Success)
                {
                    throw new CryptographicException((int)enumStatus);
                }

                // Copy the provider names into a managed array
                NCryptProviderName[] providers = new NCryptProviderName[providerCount];
                for (uint i = 0; i < providers.Length; ++i)
                {
                    providers[i] = providerBuffer.ReadArray <NCryptProviderName>(i);
                }

                return(providers);
            }
            finally
            {
                if (providerBuffer != null)
                {
                    providerBuffer.Dispose();
                }
            }
        }
Beispiel #2
0
        public static String[] EnumProviders()
        {
            UInt32 dwProviderCount = 0;
            IntPtr providerNames   = IntPtr.Zero;

            if (NCryptEnumStorageProviders(ref dwProviderCount, ref providerNames, 0) != ERROR_SUCCESS)
            {
                throw new Win32Exception("NCryptEnumStorageProviders failed.");
            }

            String[] providerNamesArray = new String[dwProviderCount];
            for (UInt32 i = 0; i < dwProviderCount; i++)
            {
                NCryptProviderName providerName = (NCryptProviderName)Marshal.PtrToStructure(new IntPtr(providerNames.ToInt64() + Marshal.SizeOf(typeof(NCryptProviderName)) * i), typeof(NCryptProviderName));

                providerNamesArray[i] = providerName.pszName;
            }

            if (NCryptFreeBuffer(providerNames) != ERROR_SUCCESS)
            {
                throw new Win32Exception("NCryptFreeBuffer failed.");
            }

            return(providerNamesArray);
        }
Beispiel #3
0
 public static extern unsafe SECURITY_STATUS NCryptEnumStorageProviders(
     out int pdwProviderCount,
     out NCryptProviderName* ppProviderList,
     NCryptEnumStorageProvidersFlags dwFlags = NCryptEnumStorageProvidersFlags.None);