title: Identification of private key in Pkcs11Interop.PDF library
body: <p>I am trying to setup up an example application with the <a href="http://www.pkcs11interop.net/extensions/pdf/" rel="nofollow">Pkcs11Interop.PDF</a> extension. I am unfortunately getting a <code>System.ArgumentNullException</code> setting the ckaId. What would work here? I tried different numbers here which all gave me a <code>System.ArgumentOutOfRangeException</code>.</p>
  
  <p>The setup is using the VirtualCryptoki-64-1.0.6.7.exe application to simulate a Smartcard.</p>
  
  <p>The troubling call is:</p>
  
  <pre><code>pkcs11RsaSignature = new Pkcs11RsaSignature(libraryPath, tokenSerial, tokenLabel, pin, ckaLabel, ckaId, hashAlgorithm);
  </code></pre>
  
  <p>The hash algorithm I use is:</p>
  
  <pre><code>HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
  </code></pre>
  
  <p><strong>Update after using the pkcs11-tool:</strong></p>
  
  <p>The content of the virtual card is:</p>
  
  <pre><code>    C:\Program Files\OpenSC Project\OpenSC\tools&gt;pkcs11-tool.exe --module "C:\windows\System32\vcki.dll" --list-slots --list-objects --login --pin 1234
  Available slots:
  Slot 0 (0xd47db04d): Virtual Smart Card Reader
    token label:   Virtual SC-A0101010101
    token manuf:   Cryptware
    token model:   VirtualSmartCard
    token flags:   rng, login required, PIN initialized, token initialized, other flags=0x200
    serial num  :
  Using slot 0 with a present token (0xd47db04d)
  Certificate Object, type = X.509 cert
    label:      ibisit
    ID:         4a656e73204b6175666d616e6e
  Public Key Object; RSA 1024 bits
    label:      ibisit
    ID:         4a656e73204b6175666d616e6e
    Usage:      encrypt, verify
  Private Key Object; RSA
    label:      ibisit
    ID:         4a656e73204b6175666d616e6e
    Usage:      decrypt, sign
  warning: PKCS11 function C_GetAttributeValue(ALWAYS_AUTHENTICATE) failed: rv = CKR_ATTRIBUTE_TYPE_INVALID (0x12)
  
  Public Key Object; RSA 1024 bits
    label:      ibisit
    ID:         4a656e73204b6175666d616e6e
    Usage:      encrypt, verify
  Private Key Object; RSA
    label:      ibisit
    ID:         4a656e73204b6175666d616e6e
    Usage:      decrypt, sign
  warning: PKCS11 function C_GetAttributeValue(ALWAYS_AUTHENTICATE) failed: rv = CKR_ATTRIBUTE_TYPE_INVALID (0x12)
  </code></pre>
  
  <p>The parameters I use are:</p>
  
  <pre><code>string libraryPath = @"C:\Windows\System32\vcki.dll";
  string tokenSerial = null;
  string tokenLabel = @"Virtual SC-A0101010101";
  string pin = @"1234";
  string ckaLabel = @"ibisit";
  string ckaId = "4a656e73204b6175666d616e6e";
  HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
  </code></pre>
  
  <p>I am unfortunatly getting a <code>Net.Pkcs11Interop.PDF.ObjectNotFoundException</code> setting the ckaId. Changing the pin gives me a different exception so I am definetely accessing the right device here.</p>
  
  <p><strong>Update after switching to SoftHSM:</strong>
  jariq stated that too many objects with the same id were there problem here. Unfortunately the Virtual Key Explorer would not let me delete any object so I switched to SoftHSM (which I was using at the beginning). I am getting "Certificate with label "ibis-it key" and id "A1B2" was not found". I suppose the problem here is that this virtual card only holds a RSA keypair not a certificate.</p>
  
  <p>The output of the pkcs11-tool is: </p>
  
  <pre><code>C:\Program Files (x86)\OpenSC Project\OpenSC\tools&gt;pkcs11-tool.exe --module "C:\SoftHSM\lib\libsofthsm.dll" --list-slots --list-objects --login --pin smart
  Available slots:
  Slot 0 (0x0): SoftHSM
    token label:   SoftHSM
    token manuf:   SoftHSM
    token model:   SoftHSM
    token flags:   rng, login required, PIN initialized, token initialized, other flags=0x40
    serial num  :  1
  Using slot 0 with a present token (0x0)
  Public Key Object; RSA 2048 bits
    label:      ibis-it key
    ID:         a1b2
    Usage:      verify
  Private Key Object; RSA
    label:      ibis-it key
    ID:         a1b2
    Usage:      sign
  </code></pre>
  
  <p>The Problem is that SoftHSM only imports PKCS#8 (RSA) key pairs, so there will never be a certificate here. I suppose you have been using it with RSA key pairs but not with certificates.</p>