Beispiel #1
0
        /// <summary>
        /// Вернет список типолв криптопровайдеров
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, int> GetProviderTypes()
        {
            Dictionary <string, int> installedCSPs = new Dictionary <string, int>();
            uint          cbName;
            uint          dwType;
            uint          dwIndex;
            StringBuilder pszName;

            dwIndex = 0;
            dwType  = 1;
            cbName  = 0;
            while (CryptoApi.CryptEnumProviderTypes(dwIndex, IntPtr.Zero, 0, ref dwType, null, ref cbName))
            {
                pszName = new StringBuilder((int)cbName);

                if (CryptoApi.CryptEnumProviderTypes(dwIndex++, IntPtr.Zero, 0, ref dwType, pszName, ref cbName))
                {
                    installedCSPs.Add(pszName.ToString(), (int)dwType);
                }
                else
                {
                    throw CreateWin32Error();
                }
            }
            return(installedCSPs);
        }