createKeyFromCSP Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - Digital Signatures

createKeyFromCSP Method

[This feature was first implemented for MSXML 5.0.]

Extracts a key from a specified cryptographic service provider (CSP) and a specified key container. The resultant key can be used to sign or verify a signature.

[JScript]

Script Syntax

var objKey = objXMLDigitalSignature.createKeyFromCSP(
      cspType, 
      cspName, 
      keyContainerName, 
      flag); 
[Visual Basic]

Visual Basic Syntax

var objKey = objXMLDigitalSignature.createKeyFromCSP( _
      cspType, _ 
      cspName, _ 
      keyContainerName, _ 
      flag)
[C/C++]

C/C++ Syntax Using Smart Pointers

IXMLDSigKeyPtr objKey = 
   objXMLDigitalSignature->createKeyFromCSP(
      long cspType, 
      _bstr_t cspName, 
      _bstr_t keyContainerName, 
      DWORD flag
   ); 

C/C++ Syntax

HRESULT createKeyFromCSP(
    long cspType, 
    BSTR cspName,
    BSTR keyContainerName,
    long flag,
    IXMLDSigKey** objKey);

Parameters

cspType
A cryptographic service provider (CSP) type as defined in CryptoAPI. Only PROV_RSA_FULL and PROV_DSS_DH are supported.
cspName
The name of the CSP. To use the default provider, set this to an empty string ("").
keyContainerName
The name of the key container within the specified CSP. The container holds the key or keys issued by a certificate authority.
flag
Reserved. Must be zero.
objKey [out, retval]
In C/C++ this points to a key object implementing the IXMLDSigKey interface. In JScript, Visual Basic, and C/C++ with smart pointer class wrappers, this is the key object itself. The resultant key object can then be used in the call to the sign method or the verifiy method.

Return Values

This methods returns the standard CryptoAPI return values, including the following:

S_OK
The value returned if successful.
E_FAIL
The value returned if there was insufficient information, if the method call was not authorize, etc.
E_ACCESSDENIED
The value returned if the user does not have access to the security item.

Remarks

A digital certificate must have been installed locally for the createKeyFromCSP method to work properly.

Example

This example illustrates how to use the createKeyFromCSP method to generate a cryptographic key from the installed CSP, and uses this key to sign a document.

We've provided source files for the sample in three languages: JScript, Visual Basic, and C++. The output is the same in each language.

Applies To

IXMLDigitalSignature | IXMLDigitalSignatureEx

Versioning

MSXML 5.0 and later

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IXMLDigitalSignatureEx | createKeyFromCertContext Method | createKeyFromHMACSecret Method | createKeyFromHMACSectetBinary Method | createKeyFromNode Method | sign Method | verify Method