/* * SafeCritical - we're not exposing out anything that we want to prevent untrusted code from getting at */ public CapiHashAlgorithm( string provider, CapiNative.ProviderType providerType, CapiNative.AlgorithmId algorithm) { Contract.Requires(!string.IsNullOrEmpty(provider)); Contract.Requires((CapiNative.AlgorithmClass)((uint)algorithm & (uint)CapiNative.AlgorithmClass.Hash) == CapiNative.AlgorithmClass.Hash); m_algorithmId = algorithm; m_cspHandle = CapiNative.AcquireCsp(null, provider, providerType, CapiNative.CryptAcquireContextFlags.VerifyContext, true); m_hashHandle = Initialize(); }
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); }
public static extern bool CryptAcquireContext(out SafeCspHandle phProv, string pszContainer, string pszProvider, CapiNative.ProviderType dwProvType, CapiNative.CryptAcquireContextFlags dwFlags);
public CapiHashAlgorithm(string provider, CapiNative.ProviderType providerType, CapiNative.AlgorithmId algorithm) { this.m_algorithmId = algorithm; this.m_cspHandle = CapiNative.AcquireCsp(null, provider, providerType, CapiNative.CryptAcquireContextFlags.None | CapiNative.CryptAcquireContextFlags.VerifyContext, true); this.Initialize(); }