Removes the certificate and its associated public/private key container from the default certificate store.
Syntax:
- <lRetVal> = object.RemoveCertificateAndKeyContainer(<sSubjectName>, <sIssuerName>, <sHexSerialNumber>, [<sServiceProvider>], [<lProviderType>])
Parameters:
- sSubjectName – Subject name of certificate to export.
- sIssuerName – Issuer name of certificate.
- sHexSerialNumber – Serial number of the certificate in hexadecimal notation.
- sServiceProvider – Optional. Cryptographic Service Provider (CSP) that has the associated private key container to remove in its database. If none is specified, the default CSP is used.
- lProviderType – Optional. CSP type. If none is specified then the default provider type is used. If the sServiceProvider name has been specified then the provider type of that service provider is used. For the list of possible provider types please see Cryptographic Service Provider Type Constants.
Returns:
Returns 1 if the operation is successful; otherwise returns 0 if the operation fails.
Remarks:
The sSubjectName, sIssuerName and sHexSerialNumber are used to search for the certificate in the certificate store. See Locating a Digital Certificate.
The sServiceProvider and lProviderType specify the database containing the private key to remove. If the private key is not found in the CSP database, a warning is generated but the certificate will still be removed. If sServiceProvider and/or lProviderType are not specified, the default CSP database is used, which is specified by DefaultProviderName and ServiceProviderType. The type of database, whether machine key set or user key set, is specified using ediDocument.Option by the constant OptDocument_MachineKeySet.
The default certificate store is specified by the properties DefaultCertSystemStoreName andDefaultCertSystemStoreLocation.
Note: The certificate is only removed from the certificate store but the certificate file is not physically deleted from the system
Example:
Dim oEdiDoc As Fredi.ediDocument
Dim oSecurities As Fredi.ediSecurities
' Create instance of Framework EDI.
Set oEdiDoc = New Fredi.ediDocument
' Get securities object.
Set oSecurities = oEdiDoc.GetSecurities
' Set the default certificate store
oSecurities.DefaultCertSystemStoreName = "My" ' Case sensitive
' Set the default certificate store location
oSecurities.DefaultCertSystemStoreLocation = "CurrentUser"
' Set the default Provider if different.
' Key container is located in the database of this service provider.
oSecurities.DefaultProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"
If Not oSecurities.IsCertificateExists("Edidev Test Certificate") Then
MsgBox "Test certificate 'Edidev Test Certificate' does not exists in certificate store."Else
If oSecurities.RemoveCertificateAndKeyContainer("Edidev Test Certificate", "Edidev Test Certificate", "") = 1 ThenEnd If
MsgBox "Successfully removed test certificate 'Edidev Test Certificate' and key container 'EdidevTestKeyContainer'."Else
MsgBox "Failed to remove test certificate"End If
Sample