public static List <ProviderAlgorithm> GetProviderAlgorithms(SafeProvHandleImpl providerHandler) { List <ProviderAlgorithm> algorithms = new List <ProviderAlgorithm>(); uint dataLen = 0; PROVENUMALGS_EX alg; if (CryptoApi.CryptGetProvParam(providerHandler, Constants.PP_ENUMALGS_EX, (byte[])null, ref dataLen, 0x1)) { var byteBuffer = new byte[dataLen]; if (CryptoApi.CryptGetProvParam(providerHandler, Constants.PP_ENUMALGS_EX, byteBuffer, ref dataLen, 0x1)) { alg = getAlgInfo(byteBuffer); algorithms.Add(new ProviderAlgorithm(alg)); while (CryptoApi.CryptGetProvParam(providerHandler, Constants.PP_ENUMALGS_EX, (byte[])null, ref dataLen, 0x2)) { byteBuffer = new byte[dataLen]; if (CryptoApi.CryptGetProvParam(providerHandler, Constants.PP_ENUMALGS_EX, byteBuffer, ref dataLen, 0x2)) { alg = getAlgInfo(byteBuffer); algorithms.Add(new ProviderAlgorithm(alg)); } } } } else { throw CreateWin32Error(); }; unsafe PROVENUMALGS_EX getAlgInfo(byte[] buff) { PROVENUMALGS_EX result; fixed(void *h = buff) { var ptr = new IntPtr(h); result = Marshal.PtrToStructure <PROVENUMALGS_EX>(ptr); //var handle = GCHandle.Alloc(buff, GCHandleType.Pinned); //var a = Marshal.PtrToStructure<PROVENUMALGS>(handle.AddrOfPinnedObject()); //handle.Free(); } return(result); } return(algorithms); }
public static string GetProviderParameterAsString(SafeProvHandleImpl providerHandle, uint paramId) { StringBuilder paramValue = null; uint dwDataLen = 0; if (CryptoApi.CryptGetProvParam(providerHandle, paramId, paramValue, ref dwDataLen, 0)) { paramValue = new StringBuilder((int)dwDataLen); CryptoApi.CryptGetProvParam(providerHandle, paramId, paramValue, ref dwDataLen, 0); } else { throw CreateWin32Error(); } return(paramValue?.ToString()); }