How to load a pkcs12 file in to KeyStore object?

Posted on 2008-06-12
Last Modified: 2013-12-22
I'm not able to extract my private key from pkcs12 file which was loaded in to KeyStore object .

ksp = KeyStore.getInstance("PKCS12");

            fis = new FileInputStream(policyFile);

            ksp.load(fis, null);

      System.out.println("size of the ksp::"+ksp.size());//---- return 0

            char[] privateKeyPassword = access_policy.toCharArray();


            PrivateKey key = (PrivateKey) ksp.getKey("XXXXX"

                    + access_policy.toLowerCase(), privateKeyPassword);

            Signature s = Signature.getInstance("SHA1withRSA");


Open in new window

Question by:vpram86
  • 2

Accepted Solution

mbodewes earned 125 total points
ID: 21771455
Have you tried filling in the password in the load() method instead? PKCS#12 is a password encrypted file, so I am wondering if just supplying the password for the key alias works (my guess is not, please reply if this doesn't work, I'll look for my PKCS#12 code at work).

Expert Comment

ID: 21912627

Featured Post

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Three simple tips to quickly and efficiently back up and protect the contents of your PC and Mac®.
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now