PrivateKey.Open method

[The Open method is available for use in the operating systems specified in the Requirements section. Instead, use the X509Certificate2.PrivateKey Property in the System.Security.Cryptography.X509Certificates namespace.]

The Open method accesses an existing key container. This method associates the key container to the certificate that corresponds to the private key by adding the CERT_KEY_PROV_INFO_PROP_ID property using the specified information.

Syntax

PrivateKey.Open( _
  ByVal ContainerName, _
  [ ByVal ProviderName ], _
  [ ByVal ProviderType ], _
  [ ByVal KeySpec ], _
  [ ByVal StoreLocation ], _
  [ ByVal bCheckExistence ] _
)

Parameters

ContainerName [in]

A string that contains the name of the key container.

ProviderName [in, optional]

A string that contains the name of the provider. The default value is CAPICOM_PROV_MS_ENHANCED_PROV. This parameter can be one of the following values.

Value Meaning
CAPICOM_PROV_MS_DEF_PROV
Microsoft base cryptographic provider.
CAPICOM_PROV_MS_ENHANCED_PROV
Microsoft enhanced cryptographic provider.
CAPICOM_PROV_MS_STRONG_PROV
Microsoft strong cryptographic provider.
CAPICOM_PROV_MS_DEF_RSA_SIG_PROV
Microsoft RSA signature cryptographic provider.
CAPICOM_PROV_MS_DEF_RSA_SCHANNEL_PROV
Microsoft RSA Schannel cryptographic provider.
CAPICOM_PROV_MS_DEF_DSS_PROV
Microsoft base DSS cryptographic provider.
CAPICOM_PROV_MS_DEF_DSS_DH_PROV
Microsoft base DSS and Diffie-Hellman cryptographic provider.
CAPICOM_PROV_MS_ENH_DSS_DH_PROV
Microsoft enhanced DSS and Diffie-Hellman cryptographic provider.
CAPICOM_PROV_MS_DEF_DH_SCHANNEL_PROV
Microsoft DH Schannel cryptographic provider.
CAPICOM_PROV_MS_SCARD_PROV
Microsoft base smart card cryptographic provider.
CAPICOM_PROV_MS_ENH_RSA_AES_PROV
Microsoft enhanced RSA and AES cryptographic provider.

 

ProviderType [in, optional]

A value of the CAPICOM_PROV_TYPE enumeration that specifies a provider type. The default value is CAPICOM_PROV_RSA_FULL. This parameter can be one of the following values.

Value Meaning
CAPICOM_PROV_RSA_FULL
The full RSA cryptographic service provider (CSP). This provider type supports both digital signatures and data encryption.
CAPICOM_PROV_RSA_SIG
The subset of the RSA CSP that supports only those functions and algorithms that are required for hashes and digital signatures.
CAPICOM_PROV_DSS
The Digital Signature Standard (DSS) CSP. This provider type supports only hashes and digital signatures. DSS uses the Digital Signature Algorithm (DSA).
CAPICOM_PROV_FORTEZZA
The CSP that contains the cryptographic protocols and algorithms owned by the National Institute of Standards and Technology (NIST).
CAPICOM_PROV_MS_EXCHANGE
The CSP that supports the Microsoft Exchange mail application and other applications that are compatible with Microsoft Mail.
CAPICOM_PROV_SSL
The CSP that supports the Secure Sockets Layer (SSL) protocol.
CAPICOM_PROV_RSA_SCHANNEL
The CSP that supports both RSA and Schannel protocols.
CAPICOM_PROV_DSS_DH
The CSP that supports both DSS and Diffie-Hellman protocols.
CAPICOM_PROV_EC_ECDSA_SIG
The CSP that supports the Elliptic Curve Digital Signature Algorithm (ECDSA) functions and algorithms required for digital signatures.
CAPICOM_PROV_EC_ECNRA_SIG
The CSP that supports the Elliptic Curve Nyberg-Rueppel Analog (ECNRA) functions and algorithms required for digital signatures.
CAPICOM_PROV_EC_ECDSA_FULL
The CSP that supports the full ECDSA.
CAPICOM_PROV_EC_ECNRA_FULL
The CSP that supports the full ECNRA.
CAPICOM_PROV_DH_SCHANNEL
The CSP that supports both Diffie-Hellman and Schannel protocols.
CAPICOM_PROV_SPYRUS_LYNKS
The CSP that supports the SPYRUS LYNKS Card device.
CAPICOM_PROV_RNG
The CSP that handles random number generation.
CAPICOM_PROV_INTEL_SEC
The CSP that provides Intel security.
CAPICOM_PROV_REPLACE_OWF
The CSP that supports replacement of the manner in which one-way formats are generated from passwords.
CAPICOM_PROV_RSA_AES
The CSP that supports both digital signatures and data encryption using the Advanced Encryption Standard (AES) algorithm.

 

KeySpec [in, optional]

A value of the CAPICOM_KEY_SPEC enumeration that specifies the type of private key. The default value is CAPICOM_KEY_SPEC_SIGNATURE. This parameter can be one of the following values.

Value Meaning
CAPICOM_KEY_SPEC_KEYEXCHANGE
The key can be used for encryption and signing.
CAPICOM_KEY_SPEC_SIGNATURE
The key can be used only for signing.

 

StoreLocation [in, optional]

A value of the CAPICOM_STORE_LOCATION enumeration that specifies the location of the store where the key resides. The default value is CAPICOM_CURRENT_USER_STORE. This parameter can be one of the following values.

Value Meaning
CAPICOM_MEMORY_STORE
The store is a memory store. Any changes in the contents of the store are not persisted.
CAPICOM_LOCAL_MACHINE_STORE
The store is a local computer store. Local computer stores can be read/write stores only if the user has read/write permissions. If the user has read/write permissions and if the store is opened read/write, then changes in the contents of the store are persisted.
CAPICOM_CURRENT_USER_STORE
The store is a current user store. A current user store may be a read/write store. If it is, changes in the contents of the store are persisted.
CAPICOM_ACTIVE_DIRECTORY_USER_STORE
The store is an Active Directory store. Active Directory stores can be opened only in read-only mode. Certificates cannot be added to or removed from Active Directory stores.
CAPICOM_SMART_CARD_USER_STORE
The store is the group of present smart cards. Introduced in CAPICOM 2.0.

 

bCheckExistence [in, optional]

A Boolean value that indicates whether CAPICOM will attempt to access the key. If True, CAPICOM attempts to access the key. If the key is user protected or on a smart card or other device, a dialog box may be generated. The default value is False.

Return value

This method does not return a value.

Remarks

This method returns CAPICOM_E_NOT_ALLOWED when it is scripted from a web-based application.

Requirements

Requirement Value
Redistributable
CAPICOM 2.0 or later on Windows Server 2003 and Windows XP
DLL
Capicom.dll

See also

PrivateKey

Certificate.HasPrivateKey