Пример #1
0
        private static bool kull_m_crypto_CryptGetProvParam(IntPtr hProv, uint dwParam, bool withError, IntPtr data, ref uint cbData, ref uint simpleDWORD)
        {
            bool   status       = false;
            uint   dwSizeNeeded = 0;;
            IntPtr psimpleDWORD = Marshal.AllocHGlobal(sizeof(uint));

            if (simpleDWORD != 0)
            {
                dwSizeNeeded = sizeof(uint);
                if (Natives.CryptGetProvParam(hProv, dwParam, psimpleDWORD, ref dwSizeNeeded, 0))
                {
                    simpleDWORD = (uint)Marshal.ReadInt32(psimpleDWORD);
                    status      = true;
                }
                else if (withError)
                {
                    Console.WriteLine("CryptGetProvParam(simple DWORD)");
                }
            }
            else
            {
                if (Natives.CryptGetProvParam(hProv, dwParam, IntPtr.Zero, ref dwSizeNeeded, 0))
                {
                    data = Marshal.AllocHGlobal((int)dwSizeNeeded);
                    if (data != IntPtr.Zero)
                    {
                        if (Natives.CryptGetProvParam(hProv, dwParam, data, ref dwSizeNeeded, 0))
                        {
                            if (cbData != 0)
                            {
                                cbData = dwSizeNeeded;
                            }
                            status = true;
                        }
                        else
                        {
                            if (withError)
                            {
                                Console.WriteLine("CryptGetProvParam(data)");
                            }
                            Marshal.FreeHGlobal(data);
                        }
                    }
                }
                else if (withError)
                {
                    Console.WriteLine("CryptGetProvParam(init)");
                }
            }
            return(status);
        }