CryptReleaseContext

The CryptReleaseContext function is used to release a handle to a CSP and a key container.

This should be performed when the application is finished using the CSP. After this function is called, the CSP handle specified by the hProv parameter will no longer be valid. Neither the key container nor any key pairs are destroyed by this function.

#include <wincrypt.h>
BOOL WINAPI CryptReleaseContext(
  HCRYPTPROV hProv,  // in
  DWORD dwFlags      // in
);
 

Parameters

hProv
Handle to the application's CSP. This is the handle the application obtains by using the CryptAcquireContext function.
dwFlags
Flag values. This parameter is reserved for future use and should always be zero.

Return Values

If the function succeeds, the return value is TRUE. If it fails, then the return value is FALSE. To retrieve extended error information, use the GetLastError function.

The following table lists the error codes most commonly returned by the GetLastError function. The error codes prefaced by "NTE" are generated by the particular CSP you are using.

Error code Description
ERROR_BUSY The CSP context specified by hProv is currently being used by another process.
ERROR_INVALID_HANDLE One of the parameters specifies an invalid handle.
ERROR_INVALID_PARAMETER One of the parameters contains an invalid value. This is most often an illegal pointer.
NTE_BAD_FLAGS The dwFlags parameter is nonzero.
NTE_BAD_UID The hProv parameter does not contain a valid context handle.

Remarks

After this function has been called, the session is over, and all existing session keys and hash objects that were created by using the hProv handle become invalid. In practice, all of these objects should be destroyed (with the CryptDestroyKey and CryptDestroyHash functions) before the CryptReleaseContext function is called.

Example

See CryptHashSessionKey.

QuickInfo

  Windows NT: Requires version 4.0 or later.
  Windows: Requires Windows 95 OSR2 or later (or Windows 95 with IE 3.02 or later).
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use advapi32.lib.

See Also

CryptAcquireContext, CryptDestroyKey, CryptDestroyHash