0

I am writing a java program that needs to read a USB Token Flash Private Key to do something, but I got stuck in the first phase of this program and it throws Error like this:

Exception in thread "main" java.security.ProviderException: Initialization failed
    at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:377)
    at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:108)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TOKEN_NOT_PRESENT
    at sun.security.pkcs11.wrapper.PKCS11.C_GetTokenInfo(Native Method)
    at sun.security.pkcs11.Token.<init>(Token.java:135)
    at sun.security.pkcs11.SunPKCS11.initToken(SunPKCS11.java:969)
    at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:368)
    ... 2 more

Here's the peice of code that represents the error above:


    String pkcs11Config = "name=eToken\nlibrary=C:\\Windows\\System32\\ShuttleCsp11_3003.dll";
    System.out.println("step 1");
    java.io.ByteArrayInputStream pkcs11ConfigStream = new java.io.ByteArrayInputStream(pkcs11Config.getBytes());
    Provider providerPKCS11 = new sun.security.pkcs11.SunPKCS11(pkcs11ConfigStream);
    java.security.Security.addProvider(providerPKCS11);
    System.out.println("step 2");

I tried to reinstall the program which is inside this USB flash and I could successfully login and export public key and certificate. I even restarted the pc, but none of them worked and I still got those errors. Do you think my USB Token is corrupted or damaged? Cause if it is damaged it shouldn't login successfully...

I expect to pass this line of code:

Provider providerPKCS11 = new sun.security.pkcs11.SunPKCS11(pkcs11ConfigStream);

Can someone please help me with this code?

2
  • Are you sure your token was designed to be used in this way? Not all tokens are created equal. Commented Sep 27, 2023 at 18:22
  • @TimRoberts Hello, Yes I'm sure. Actually I searched for tokens like the one mentioned and found out I should use a library (in my case DLL) to communicate with them and this .dll library can retrieve private key when it's used along with custom packages and libraries form other programming languages (like java) but, it still doesn't let user to see what the private key is. I recently found out that when I install .exe program inside this USB Flash Token, it copies 2 .dll files and 1 .sig file in "C:\Windows\System32" folder and that's as far as I went. Commented Sep 27, 2023 at 18:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.