cryptacquirecontext (advapi32)
Last changed: -212.154.152.136

.
Summary
Used to acquire a handle to a particular key container within a particular cryptographic service provider (CSP).

C# Signature:

[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
[return : MarshalAs(UnmanagedType.Bool)]
   static extern bool CryptAcquireContext(ref IntPtr hProv, string pszContainer,
   string pszProvider, uint dwProvType, uint dwFlags);

VB .NET Signature:

Declare Function CryptAcquireContext Lib "advapi32.dll" (ByRef hProv As IntPtr, _
   pszContainer As String, pszProvider As String, dwProvType As Integer, _
   dwFlags As Integer) As Boolean

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

static long CRYPT_NEWKEYSET = 0x8;

static long CRYPT_DELETEKEYSET = 0x10;

static long CRYPT_MACHINE_KEYSET = 0x20;

static long CRYPT_SILENT = 0x40;

static long CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x80;

static long CRYPT_VERIFYCONTEXT = 0xF0000000;

static int PROV_RSA_FULL = 1;

Sample Code:

public class Crypt32 { [DllImport("advapi32.dll", SetLastError=true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool CryptAcquireContext(
        out IntPtr phProv,
        string pszContainer,
        string pszProvider,
        uint dwProvType,
        uint dwFlags);}

.......

IntPtr hProv = new IntPtr();

bool res = Crypt32.CryptAcquireContext(out hProv, "user", null, PROV_RSA_FULL, CRYPT_NEWKEYSET);

Alternative Managed API:

TODO

Documentation