public static IEnumerable <CngAlgorithm> GetSupportedAlgorithms(this CngProvider provider, NCryptAlgorithmOperations operations) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { foreach (NCryptNative.NCryptAlgorithmName algorithm in NCryptNative.EnumerateAlgorithms(providerHandle, operations)) { yield return(new CngAlgorithm(algorithm.pszName)); } } }
public static IEnumerable <CngAlgorithm> GetSupportedAlgorithms(this CngProvider provider, NCryptAlgorithmOperations operations) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { NCryptNative.NCryptAlgorithmName[] algorithmNames = NCryptNative.EnumerateAlgorithms(providerHandle, operations); CngAlgorithm[] algorithms = new CngAlgorithm[algorithmNames.Length]; for (int i = 0; i < algorithmNames.Length; ++i) { algorithms[i] = new CngAlgorithm(algorithmNames[i].pszName); } return(algorithms); } }
internal static NCryptAlgorithmName[] EnumerateAlgorithms(SafeNCryptProviderHandle provider, NCryptAlgorithmOperations operations) { Debug.Assert(provider != null && !provider.IsClosed && !provider.IsInvalid, "Invalid provider"); uint algorithmCount = 0; SafeNCryptBuffer algorithmBuffer = null; try { // Ask CNG for the list of algorithms ErrorCode enumStatus = UnsafeNativeMethods.NCryptEnumAlgorithms(provider, operations, out algorithmCount, out algorithmBuffer, 0); if (enumStatus != ErrorCode.Success) { throw new CryptographicException((int)enumStatus); } // Copy the algorithm names into a managed array NCryptAlgorithmName[] algorithms = new NCryptAlgorithmName[algorithmCount]; for (uint i = 0; i < algorithms.Length; ++i) { algorithms[i] = algorithmBuffer.ReadArray <NCryptAlgorithmName>(i); } return(algorithms); } finally { if (algorithmBuffer != null) { algorithmBuffer.Dispose(); } } }
internal static extern ErrorCode NCryptEnumAlgorithms(SafeNCryptProviderHandle hProvider, NCryptAlgorithmOperations dwAlgOperations, [Out] out uint pdwAlgCount, [Out] out SafeNCryptBuffer ppAlgList, int dwFlags);
public static IEnumerable<CngAlgorithm> GetSupportedAlgorithms(this CngProvider provider, NCryptAlgorithmOperations operations) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { foreach (NCryptNative.NCryptAlgorithmName algorithm in NCryptNative.EnumerateAlgorithms(providerHandle, operations)) { yield return new CngAlgorithm(algorithm.pszName); } } }