IX509PrivateKey::Create method (certenroll.h)

The Create method creates an asymmetric private key.

Syntax

HRESULT Create();

Return value

If the function succeeds, the function returns S_OK.

If the function fails, it returns an HRESULT value that indicates the error. Possible values include, but are not limited to, those in the following table. For a list of common error codes, see Common HRESULT Values.

Return code/value Description
HRESULT_FROM_WIN32(ERROR_BUSY)
The CSP handle is not NULL.
HRESULT_FROM_WIN32(ERROR_FILE_EXISTS)
The key already exists.

Remarks

If you do not set the CspStatus, the ProviderName, or ProviderType properties, this method uses the default provider, key size, and KeySpec values when creating the key. On a new operating system installation, for example, Microsoft Enhanced Cryptographic Provider v1.0 is the default provider.

If you do not set the ContainerName property, this method automatically generates a name. The generated name includes a GUID and, if the ContainerNamePrefix property is not set, a prefix of "lp-". If the provider is a smart card provider, the generated name will not exceed the MaxKeyContainerNameLength value specified by the provider. If the generated name initially exceeds this value, it is truncated to forty characters.

You cannot set the following properties after calling the Create or Open methods. If you wish to specify them, you must do so before calling either of these methods.

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header certenroll.h
DLL CertEnroll.dll

See also

IX509PrivateKey