Example #1
0
        public static SafeProvHandleImpl CreateProvider(CspParameters providerParameters)
        {
            var providerHandle = SafeProvHandleImpl.InvalidHandle;

            if (!CryptoApi.CryptAcquireContext(ref providerHandle, providerParameters.KeyContainerName, providerParameters.ProviderName, (uint)providerParameters.ProviderType, Constants.CRYPT_NEWKEYSET))
            {
                throw CreateWin32Error();
            }

            return(providerHandle);
        }
Example #2
0
        public static SafeProvHandleImpl OpenProvider(CspParameters providerParameters)
        {
            var providerHandle = SafeProvHandleImpl.InvalidHandle;
            var dwFlags        = MapCspProviderFlags(providerParameters.Flags);

            if (!CryptoApi.CryptAcquireContext(ref providerHandle, providerParameters.KeyContainerName, providerParameters.ProviderName, (uint)providerParameters.ProviderType, dwFlags))
            {
                throw CreateWin32Error();
            }

            return(providerHandle);
        }
Example #3
0
        public static SafeProvHandleImpl AcquireProvider(CspParameters providerParameters)
        {
            var providerHandle = SafeProvHandleImpl.InvalidHandle;

            var dwFlags = Constants.CRYPT_VERIFYCONTEXT;

            if ((providerParameters.Flags & CspProviderFlags.UseMachineKeyStore) != CspProviderFlags.NoFlags)
            {
                dwFlags |= Constants.CRYPT_MACHINE_KEYSET;
            }

            if (!CryptoApi.CryptAcquireContext(ref providerHandle, providerParameters.KeyContainerName, providerParameters.ProviderName, (uint)providerParameters.ProviderType, dwFlags))
            {
                throw CreateWin32Error();
            }

            return(providerHandle);
        }
Example #4
0
        public static int OpenProvider(CspParameters providerParameters, ref SafeProvHandleImpl hProv)
        {
            uint dwFlags = MapCspProviderFlags(providerParameters.Flags);

            if (!CryptoApi.CryptAcquireContext(ref hProv, providerParameters.KeyContainerName, providerParameters.ProviderName, (uint)providerParameters.ProviderType, dwFlags))
            {
                return(Marshal.GetLastWin32Error());
            }
            return(0);


            //var providerHandle = SafeProvHandleImpl.InvalidHandle;
            //var dwFlags = MapCspProviderFlags(providerParameters.Flags);

            //if (!CryptoApi.CryptAcquireContext(ref providerHandle, providerParameters.KeyContainerName, providerParameters.ProviderName, (uint)providerParameters.ProviderType, dwFlags))
            //{
            //             throw CreateWin32Error();
            //}

            //return providerHandle;
        }