This sample demonstrates use of alternative parameters to CPKIFCAPI2 to target a specific cryptographic service provider or certificate store registry location (i.e. system vs. current user).
Supported Languages
const char* g_csp = "ActivCard
Gold Cryptographic Service Provider";
void
UsingSpecificCryptoProvider()
{
CPKIFCredentialList v;
CPKIFCredentialList::iterator pos;
CPKIFCredentialList::iterator end;
//Create an
instance targeting local machine cert store
//then get
credential list and display credential names
CPKIFCAPI2
localStore(NULL,NULL,CERT_SYSTEM_STORE_LOCAL_MACHINE);
localStore.GetKeyList(v);
for(pos =
v.begin(), end = v.end(); pos != end; ++pos)
cout << (*pos)->Name()
<< endl;
//empty the list
v.clear();
try
{
//Create
an instance targeting ActivCard CSP based keys only
//then get
credential list and display credential names
//CPKIFCAPI<g_csp,
PROV_RSA_FULL> curUserActivCardOnly;
CPKIFCAPI2
curUserActivCardOnly(g_csp, PROV_RSA_FULL);
curUserActivCardOnly.GetKeyList(v);
for(pos
= v.begin(), end = v.end(); pos != end; ++pos)
cout <<
(*pos)->Name() << endl;
}
catch(CPKIFException&)
{
//inspect
exception - will throw if ActivCard CSP not installed
}
}
string g_csp = "ActivCard Gold Cryptographic Service Provider";
public void UsingSpecificCryptoProvider()
{
CPKIFCredentialList
v = new CPKIFCredentialList();
//Create an
instance targeting local machine cert store
//then get
credential list and display credential names
IPKIFColleaguePtr
localStoreCol = pkif_module.make_NewCPKIFCAPI2(null, 0, pkif_module.CERT_SYSTEM_STORE_LOCAL_MACHINE);
CPKIFCAPI2Ptr
localStore = pkif_module.cast_ToCPKIFCAPI2(localStoreCol);
localStore.GetKeyList(v);
for (int ii = 0; ii < v.Count; ii++)
{
Console.WriteLine(v[ii].Name());
}
//empty the list
v.Clear();
try
{
//Create an
instance targeting ActivCard CSP based keys only
//then get
credential list and display credential names
CPKIFCAPI2
curUserActivCardOnly = new CPKIFCAPI2(g_csp);
curUserActivCardOnly.GetKeyList(v);
{
Console.WriteLine(v[jj].Name());
}
}
catch(Exception )
{
//inspect
exception - will throw if ActivCard CSP not installed
}
}
String g_csp = "ActivCard
Gold Cryptographic Service Provider";
public void
UsingSpecificCryptoProvider()
{
CPKIFCredentialList v = new
CPKIFCredentialList();
//Create an instance targeting local
machine cert store
//then get credential list and display
credential names
IPKIFColleaguePtr localStoreCol =
pkif_module.make_NewCPKIFCAPI2(null, 0, pkif_module.CERT_SYSTEM_STORE_LOCAL_MACHINE);
CPKIFCAPI2Ptr localStore = pkif_module.cast_ToCPKIFCAPI2(localStoreCol);
localStore.GetKeyList(v);
{
System.out.println(v.get(ii).Name());
}
//empty the list
v.size();
try
{
//Create an instance targeting
ActivCard CSP based keys only
//then get credential list and display
credential names
CPKIFCAPI2 curUserActivCardOnly = new CPKIFCAPI2(g_csp);
curUserActivCardOnly.GetKeyList(v);
for (int jj = 0; jj <
v.size(); jj++)
{
System.out.println(v.get(jj).Name());
}
}
catch(Exception e)
{
//inspect exception - will throw if
ActivCard CSP not installed
}
}