static CspCollection m_enumprovs() { Hashtable ProvTypes = get_provtypes(); StringBuilder pszProvName = new StringBuilder(); CspCollection csps = new CspCollection(); UInt32 dwIndex = 0; UInt32 pdwProvType = 0; UInt32 pcbProvName = 0; while (AdvAPI.CryptEnumProviders(dwIndex, 0, 0, ref pdwProvType, null, ref pcbProvName)) { pszProvName.Length = (Int32)pcbProvName; // retrieve CSP if (!AdvAPI.CryptEnumProviders(dwIndex++, 0, 0, ref pdwProvType, pszProvName, ref pcbProvName)) { throw new Win32Exception(Error.InvalidDataException); } String name = pszProvName.ToString(); String pType = (String)ProvTypes[pdwProvType]; IntPtr phProv = IntPtr.Zero; // retrieve CSP context if (!AdvAPI.CryptAcquireContext(ref phProv, null, name, pdwProvType, Wincrypt.CRYPT_VERIFYCONTEXT)) { throw new Win32Exception(Error.InavlidHandleException); } Int32 pdwDataLen = 0; ALG_IDCollection algs = new ALG_IDCollection(); if (AdvAPI.CryptGetProvParam(phProv, 0x16, null, ref pdwDataLen, Wincrypt.CRYPT_FIRST)) { Byte[] pbData = new Byte[Marshal.SizeOf(typeof(Wincrypt.PROV_ENUMALGS_EX))]; while (AdvAPI.CryptGetProvParam(phProv, 0x16, pbData, ref pdwDataLen, Wincrypt.CRYPT_NEXT)) { IntPtr ptr = Marshal.AllocHGlobal(pbData.Length); Marshal.Copy(pbData, 0, ptr, pbData.Length); Wincrypt.PROV_ENUMALGS_EX AlgStructure = (Wincrypt.PROV_ENUMALGS_EX)Marshal.PtrToStructure(ptr, typeof(Wincrypt.PROV_ENUMALGS_EX)); Marshal.FreeHGlobal(ptr); ALG_ID alg = get_algparams(AlgStructure); algs.Add(alg); } csps.Add(new CspLegacy(name, pType, algs)); } else { csps.Add(new CspLegacy(name, pType, algs)); } AdvAPI.CryptReleaseContext(phProv, 0); } return(csps); }
/// <summary> /// Adds an <see cref="ALG_ID"/> object to the <see cref="ALG_IDCollection"/> object. /// </summary> /// <remarks>Use this method to add an <see cref="ALG_ID"/> object to an existing collection at the current location.</remarks> /// <param name="entry">The <see cref="ALG_ID"/> object to add to the collection.</param> /// <returns>The index of the added <see cref="ALG_ID"/> object.</returns> public Int32 Add(ALG_ID entry) { return(m_list.Add(entry)); }