I have Gemalto.NET Smart Card.
I imported 2 certificates into it using Gemalto tools, which use sconnect (which as I suspect use Crypto API to do it when used in IE).
When I run
certutil -key -csp "Microsoft Base Smart Card Crypto Provider"
I have following result
Microsoft Base Smart Card Crypto Provider:
7c168bc3-dc1d-a627-c218-cd45729b42cb [Default Container] AT_KEYEXCHANGEbadd537a-a377-431b-cbc9-8699dbe15e0e AT_KEYEXCHANGE
LoadKeys returned Key does not exist. 0x8009000d (-2146893811) CertUtil: -key command completed successfully.
Now I want to find those keys in my C# program. To do it I wrote following method that should return all keys on specific smart card.
static List<string> EnumerateContainers(string card)
{
var list = new List<string>();
var provider = IntPtr.Zero;
if (!CryptAcquireContext(ref provider, @"\\.\" + card + @"\", "Microsoft Base Smart Card Crypto Provider", 1, CspProviderFlags.UseMachineKeyStore))
Debug.WriteLine("no context for " + card);
uint bufferSize = 4096;
var container = new StringBuilder((int)bufferSize);
uint flags = CRYPT_FIRST;
while(CryptGetProvParam(provider, PP_ENUMCONTAINERS, container, ref bufferSize, flags))
{
list.Add(container.ToString());
flags = 0;
}
return list;
}
But my method find only the key 7c168bc3-dc1d-a627-c218-cd45729b42cb which is the default one. What should I do to find all keys/containers stored on the smart card ??
And Later
How can I delete those keys and import new one using C#?