title: SunPkcs11: CKR_TOKEN_NOT_RECOGNIZED
body: <p>I'm trying to get certs from a smart card but when initialize the Sun PKCS11 provider I get the following error:</p>
  
  <pre><code>java.security.ProviderException: Initialization failed
      at sun.security.pkcs11.SunPKCS11.&lt;init&gt;(SunPKCS11.java:374)
      at sun.security.pkcs11.SunPKCS11.&lt;init&gt;(SunPKCS11.java:107)
  Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TOKEN_NOT_RECOGNIZED
      at sun.security.pkcs11.wrapper.PKCS11.C_GetTokenInfo(Native Method)
      at sun.security.pkcs11.Token.&lt;init&gt;(Token.java:130)
      at sun.security.pkcs11.SunPKCS11.initToken(SunPKCS11.java:804)
      at sun.security.pkcs11.SunPKCS11.&lt;init&gt;(SunPKCS11.java:365)
      ... 44 more
  </code></pre>
  
  <p>My code: </p>
  
  <pre><code>String providerConfig = "name=PKCS11\r\nlibrary=C:\\WINDOWS\\system32\\UsrPkcs11.dll\r\n";
  ByteArrayInputStream providerConfigBAIS = new ByteArrayInputStream(providerConfig.getBytes());
  sun.security.pkcs11.SunPKCS11 provider = new SunPKCS11(providerConfigBAIS);
  </code></pre>
  
  <p>¿Any idea with this error?</p>
  
  <p>Thanks in advance.</p>