Question

I use the code below to get certificate from personal keystore in java but the statement ksp.load(null,null) takes 14 seconds to execute which I am not able to figure out why and how I can reduce it. I am able to sign the pdf document with the certificate but the whole process takes 1 minute which I wanted to be 1 sec.

SunMSCAPI SunProvider=new SunMSCAPI();
Security.addProvider(SunProvider);
KeyStore ksp = KeyStore.getInstance("Windows-MY");
ksp.load(null,null);
java.security.cert.Certificate[] chain = ksp.getCertificateChain(certName);
Was it helpful?

Solution

I'm fairly certain it is the SecureRandom seeding. Cyrpto requires strong random number generation. One of the techniques for this is to run an algorithm for a long time, producing an unpredictable number at the end. Solutions might be:

  • find a way to do this "ahead of time", and that it only happens once.
  • find a crypto implementation / JVM which has a different faster implementation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top