static void ImportKey (ObjectType type, bool machine, string file, string password, bool verbose)
{
switch (type) {
case ObjectType.Certificate:
X509CertificateCollection coll = LoadCertificates (file, password, verbose);
int count = 0;
foreach (X509Certificate x509 in coll) {
RSACryptoServiceProvider pk = x509.RSA as RSACryptoServiceProvider;
if (pk == null || pk.PublicOnly)
continue;
CspParameters csp = new CspParameters ();
csp.KeyContainerName = CryptoConvert.ToHex (x509.Hash);
csp.Flags = machine ? CspProviderFlags.UseMachineKeyStore : 0;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (csp);
rsa.ImportParameters (pk.ExportParameters (true));
rsa.PersistKeyInCsp = true;
count++;
}
Console.WriteLine ("{0} keys(s) imported to KeyPair {1} persister.",
count, machine ? "LocalMachine" : "CurrentUser");
break;
default:
throw new NotSupportedException (type.ToString ());
}
}