NCryptSecretAgreement function

The NCryptSecretAgreement function creates a secret agreement value from a private and a public key.

Syntax

SECURITY_STATUS NCryptSecretAgreement(
  NCRYPT_KEY_HANDLE    hPrivKey,
  NCRYPT_KEY_HANDLE    hPubKey,
  NCRYPT_SECRET_HANDLE *phAgreedSecret,
  DWORD                dwFlags
);

Parameters

hPrivKey

The handle of the private key to use to create the secret agreement value. This key and the hPubKey key must come from the same key storage provider.

hPubKey

The handle of the public key to use to create the secret agreement value. This key and the hPrivKey key must come from the same key storage provider.

phAgreedSecret

A pointer to an NCRYPT_SECRET_HANDLE variable that receives a handle that represents the secret agreement value. When this handle is no longer needed, release it by passing it to the NCryptFreeObject function.

dwFlags

Flags that modify function behavior. This can be zero or a combination of one or more of the following values. The set of valid flags is specific to each key storage provider. The following flag applies to all providers.

Value Meaning
NCRYPT_SILENT_FLAG
Requests that the key service provider (KSP) not display any user interface. If the provider must display the UI to operate, the call fails and the KSP should set the NTE_SILENT_CONTEXT error code as the last error.

Return value

Returns a status code that indicates the success or failure of the function.

Possible return codes include, but are not limited to, the following.

Return code Description
ERROR_SUCCESS
The function was successful.
NTE_INVALID_HANDLE
The hPrivKey or the hPubKey parameter is not valid.
NTE_INVALID_PARAMETER
One or more parameters are not valid.
NTE_NO_MEMORY
A memory allocation failure occurred.

Remarks

A service must not call this function from its StartService Function. If a service calls this function from its StartService function, a deadlock can occur, and the service may stop responding.

Requirements

   
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header ncrypt.h
Library Ncrypt.lib
DLL Ncrypt.dll

See also

NCryptFreeObject