Share via


CryptReleaseContext (Compact 2013)

3/28/2014

This function frees the handle to a cryptographic service provider (CSP) and the key container. At each call to this function, the reference count on the CSP is reduced by one. When the reference count reaches zero, the context is fully freed and it can no longer be used by any function in the application.

The application calls this function when it is finished using the CSP. After this function is called, the CSP handle specified by the hProv parameter is no longer valid; however, the function does not destroy either the key container or any key pairs.

Syntax

BOOL WINAPI CryptReleaseContext( 
  HCRYPTPROV hProv,
  DWORD dwFlags
); 

Parameters

  • dwFlags
    [in] Reserved; must be set to 0 (zero).

Return Value

TRUE indicates success. FALSE indicates failure. To get extended error information, call the GetLastError function. The following table shows common values for the GetLastError function. The error values prefaced by NTE are generated by the particular CSP you are using.

Value

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 calling this function, 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 calling the CryptReleaseContext function.

Example Code

See CryptHashSessionKey.

Requirements

Header

wincrypt.h

Library

coredll.lib

See Also

Reference

Cryptography Functions
CryptAcquireContext
CryptDestroyKey
CryptDestroyHash