Adding a key to a KeyContainer...

From: Řyvind Habberstad (
Date: 09/18/02

From: (Řyvind Habberstad)
Date: 18 Sep 2002 06:09:04 -0700


In short: What happens when I add a new key to a KeyContainer?


I'm adding a privatekey generated in OpenSSL into a KeyContainer using
the following code:

private void addKeyToKeyContainer( string pathPrivKey ,
                                   string keyContainerName ) {
  CspParameters cspParams = new CspParameters(PROVIDER_RSA_FULL);
  cspParams.KeyContainerName = keyContainerName;
  cspParams.Flags = CspProviderFlags.UseMachineKeyStore;

  RSACryptoServiceProvider rsa = new
  rsa.ImportParameters( createRSAParametersFromPrivKey( pathPrivKey)
  rsa.PersistKeyInCsp = true;

After adding the key the following file is updated:
C:\Documents and Settings\All Users\Application
Data\Microsoft\Crypto\RSA\MachineKeys\9351a4083.... (something very

1. When adding a new key to the same KeyContainer, do I overwrite an
excisting key?

2. If a KeyContainer can contain several keys how do I know wich key
I'm using?

3. When I add a key to one or more KeyContainers there is only one
file that are updated and the file size does not increase noe matter
how many keys I add, why is that?

Any help is appreciated!!

Cheers, Řyvind.