Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
InitializeFromPrivateKey Method

IX509CertificateRequestPkcs10::InitializeFromPrivateKey method

The InitializeFromPrivateKey method initializes the certificate request by using an IX509PrivateKey object and, optionally, a template. This method is web enabled.


HRESULT InitializeFromPrivateKey(
  [in]           X509CertificateEnrollmentContext Context,
  [in]           IX509PrivateKey                  *pPrivateKey,
  [in, optional] BSTR                             strTemplateName


Context [in]

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. However, if the MachineContext property of the private key is set, you must specify the ContextMachine enumeration value.


The certificate is being requested for an end user.


The certificate is being requested for a computer.


The certificate is being requested by an administrator acting on the behalf of a computer.


pPrivateKey [in]

Pointer to an IX509PrivateKey interface that represents the private key.

strTemplateName [in, optional]

A BSTR variable that contains the Common Name (CN) of the template as it appears in Active Directory or the dotted decimal object identifier. This is an optional parameter.

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 codeDescription

The certificate request object has already been initialized.



If you specify a template, the InitializeFromPrivateKey method performs the following actions:

  • Adds the extensions specified by the template to an IX509Extensions collection.
  • Creates an IObjectIds 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 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.
  • Retrieves an asymmetric encryption algorithm OID, if it exists, from the template and sets it on the IX509SignatureInformation object.
  • Populates many of the IX509PrivateKey properties from the template settings.

Whether you specify a template or not, if the CSPInformations property is not specified, the method creates an ICspInformations collection from the providers installed on the computer.

No private key is created at this point. If the IX509PrivateKey object passed to the method does not represent an existing key, a key is created when the Encode method is called. The key will be created by using the default provider if no template was specified and the ProviderName property on the IX509PrivateKey is not set. When a private key exists, it is set on the PrivateKey property.


Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]





See also




Community Additions

© 2015 Microsoft