IX509CertificateRequestPkcs10V2::InitializeFromPublicKeyTemplate method (certenroll.h)

The InitializeFromPublicKeyTemplate method initializes a null-signed certificate request by using an IX509PublicKey object and a template.

Syntax

HRESULT InitializeFromPublicKeyTemplate(
  [in] X509CertificateEnrollmentContext Context,
  [in] IX509PublicKey                   *pPublicKey,
  [in] IX509EnrollmentPolicyServer      *pPolicyServer,
  [in] IX509CertificateTemplate         *pTemplate
);

Parameters

[in] Context

An X509CertificateEnrollmentContext enumeration value that specifies whether the requested certificate is intended for an end user, a computer, or an administrator acting on behalf of the computer. This can be one of the following values.

Value Meaning
ContextUser
The certificate is being requested for an end user.
ContextMachine
The certificate is being requested for a computer.
ContextAdministratorForceMachine
The certificate is being requested by an administrator acting on the behalf of a computer.

[in] pPublicKey

Pointer to an IX509PublicKey interface that represents the public key.

[in] pPolicyServer

Pointer to an IX509EnrollmentPolicyServer object that represents the certificate enrollment policy (CEP) server that contains the template specified by the pTemplate parameter.

[in] pTemplate

Pointer to an IX509CertificateTemplate object that represents the template to use during initialization.

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
E_POINTER
The pPublicKey, pPolicyServer, or pTemplate parameters are NULL.
HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED)
The certificate request object has already been initialized.

Remarks

The InitializeFromPublicKeyTemplate method performs the following actions:

  • Adds the extensions specified in the template, if any, to the IX509Extensions collection.
  • Creates a CriticalExtensions collection and populates it with the default XCN_OID_KEY_USAGE and XCN_OID_BASIC_CONSTRAINTS2 object identifiers. If the template indicates that these OIDs are not critical, they are removed from the collection. The OIDs marked critical by the template, if any, are added.
  • Sets the SmimeCapabilities property if the template supports symmetric algorithms.
  • Sets the AlternateSignatureAlgorithm property if the template requires a discrete signature algorithm OID.
  • Creates an IX509SignatureInformation object.
  • Creates a hash algorithm OID if the algorithm is specified in the template and sets it on the IX509SignatureInformation object.
  • Creates an asymmetric encryption algorithm OID if the algorithm is specified in the template and sets it on the IX509SignatureInformation object.

If the CSPInformations property is not specified, the method creates an ICspInformations collection from the providers installed on the computer.

The method does not create a private key. The use of this method implies that the request is null-signed. Therefore, the method sets the NullSigned property on the IX509SignatureInformation object.

Requirements

Requirement Value
Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header certenroll.h

See also

IX509CertificateRequestPkcs10V2