title: Programmatically add key from X509Certificate2 via PKCS#11 to a key store
body: <p>We have a secure key store which features a PKCS#11 interface. We access keys on it using the <a href="https://pkcs11interop.net/" rel="nofollow noreferrer">PKCS#11 Interop Library for .NET</a>. We also need to import keys from certificates. How to import the PrivateKey of an <code>X509Certificate2</code> via our PKCS#11 interface into our key store?</p>
  
  <pre><code>var key = x509Certificate2.PrivateKey;
  
  var attributes = new List&lt;ObjectAttribute&gt;();
  
  // What to do here? How to fill in the key into those attributes?
  
  pkcs11Session.CreateObject(attributes);
  </code></pre>