Expand Minimize

CryptReleaseContext function

The CryptReleaseContext function releases the handle of a cryptographic service provider (CSP) and a 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 released and it can no longer be used by any function in the application.

An application calls this function after finishing the use of the CSP. After this function is called, the released CSP handle is no longer valid. This function does not destroy key containers or key pairs.

Syntax


BOOL WINAPI CryptReleaseContext(
  _In_  HCRYPTPROV hProv,
  _In_  DWORD dwFlags
);

Parameters

hProv [in]

Handle of a cryptographic service provider (CSP) created by a call to CryptAcquireContext.

dwFlags [in]

Reserved for future use and must be zero. If dwFlags is not set to zero, this function returns FALSE but the CSP is released.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError. Some possible error codes are listed in the following table.

Return codeDescription
ERROR_BUSY

The CSP context specified by hProv is currently being used by another process.

ERROR_INVALID_HANDLE

One of the parameters specifies a handle that is not valid.

ERROR_INVALID_PARAMETER

One of the parameters contains a value that is not valid. This is most often a pointer that is not valid.

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 CSP session is finished and all existing session keys and hash objects created by using the hProv handle are no longer valid. In practice, all of these objects should be destroyed with calls to CryptDestroyKey and CryptDestroyHash before CryptReleaseContext is called.

Examples

For an example that uses this function, see Example C Program: Creating and Hashing a Session Key.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Wincrypt.h

Library

Advapi32.lib

DLL

Advapi32.dll

See also

Service Provider Functions
CryptAcquireContext
CryptDestroyKey
CryptDestroyHash

 

 

Community Additions

ADD
Show:
© 2014 Microsoft