CryptReleaseContext

This function is used to release a handle to a cryptographic service provider (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 is no longer valid. Neither the key container nor any key pairs are destroyed by this function.

At a Glance

Header file: Wincrypt.h
Windows CE versions: 2.10 and later

Syntax

BOOL WINAPI CryptReleaseContext( HCRYPTPROV hProv,
DWORD dwFlags );

Parameters

hProv

[in] Handle to the application's CSP. This is the handle the application obtains by using the CryptAcquireContext function.

dwFlags

[in] Specifies a bitmask of flags. This parameter is reserved for future use; set to 0.

Return Values

TRUE indicates success. FALSE indicates failure. To get extended error information, call GetLastError. Common values for GetLastError are described in the following table. 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 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.

See Also

CryptAcquireContext, CryptDestroyKey, CryptDestroyHash