Esempio n. 1
0
 public static extern bool CryptAcquireContext(out SafeCspHandle phProv, string pszContainer, string pszProvider, CapiNative.ProviderType dwProvType, CapiNative.CryptAcquireContextFlags dwFlags);
Esempio n. 2
0
        internal static SafeCspHandle AcquireCsp(string keyContainer, string providerName, CapiNative.ProviderType providerType, CapiNative.CryptAcquireContextFlags flags)
        {
            if ((flags & CapiNative.CryptAcquireContextFlags.VerifyContext) == CapiNative.CryptAcquireContextFlags.VerifyContext && (flags & CapiNative.CryptAcquireContextFlags.MachineKeyset) == CapiNative.CryptAcquireContextFlags.MachineKeyset)
            {
                flags &= ~CapiNative.CryptAcquireContextFlags.MachineKeyset;
            }
            SafeCspHandle phProv = (SafeCspHandle)null;

            if (!CapiNative.UnsafeNativeMethods.CryptAcquireContext(out phProv, keyContainer, providerName, providerType, flags))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            return(phProv);
        }