private Object CreatePrivateKey()
{
// Create a new private key for the certificate
//CX509PrivateKey lPrivateKey = new CX509PrivateKey();
Type lPrivateKeyType = Type.GetTypeFromProgID("X509Enrollment.CX509PrivateKey");
Object lPrivateKey = Activator.CreateInstance(lPrivateKeyType);
//lPrivateKey.Length = 1024;
lPrivateKeyType.InvokeMember("Length", BindingFlags.SetProperty, null, lPrivateKey, new Object[] { 1024 });
//lPrivateKey.KeySpec = X509KeySpec.XCN_AT_KEYEXCHANGE; // use is not limited
lPrivateKeyType.InvokeMember("KeySpec", BindingFlags.SetProperty, null, lPrivateKey, new Object[] { XCN_AT_KEYEXCHANGE });
//lPrivateKey.ExportPolicy = X509PrivateKeyExportFlags.XCN_NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG;
lPrivateKeyType.InvokeMember("ExportPolicy", BindingFlags.SetProperty, null, lPrivateKey, new Object[] { XCN_NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG });
//lPrivateKey.ProviderName = "Microsoft Base Cryptographic Provider v1.0";
lPrivateKeyType.InvokeMember("ProviderName", BindingFlags.SetProperty, null, lPrivateKey, new Object[] { "Microsoft Base Cryptographic Provider v1.0" });
//lPrivateKey.MachineContext = false;
lPrivateKeyType.InvokeMember("MachineContext", BindingFlags.SetProperty, null, lPrivateKey, new Object[] { false });
//lPrivateKey.Create();
lPrivateKeyType.InvokeMember("Create", BindingFlags.InvokeMethod, null, lPrivateKey, new Object[] { });
return lPrivateKey;
}