Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:31+00:00 2026-05-29T06:27:31+00:00

I am programatically loading a certificate into a default keystore with the following code

  • 0

I am programatically loading a certificate into a default keystore with the following code

KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());
java.io.FileInputStream fis = new FileInputStream(keystorePath);
kStore.load(fis, new String(keystorePass).toCharArray());
fis.close();

I have a certificate from a third party in pfx format. If I try to load it, it fails with invalid format.

If I update to use the following it works. But I don’t want to change the code.

KeyStore keystore = KeyStore.getInstance("PKCS12");  

How can I convert the pfx file to a format that will be accepted by the following

KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:27:32+00:00Added an answer on May 29, 2026 at 6:27 am

    Certificate stuff is never simple . You need openssl (the Cygwin version works on Windows) to convert the pfx / p12 file to a pem file, then you can create a certificate from the pem. Finally, you can use the Java keytool program to convert the certificate to JKS format (the KeyStore default).

    Convert the pfx to pem:

    openssl pkcs12 -in whatever.pfx -out whatever.pem -clcerts -nokeys
    

    Create an X509 certificate from the pem file:

    openssl x509 -in whatever.pem -inform PEM -out whatever.crt -outform DER
    

    Use Java’s keytool to create a JKS file from the cert:

    keytool -import -trustcacerts -keystore whatever.jks -storepass somepassword -noprompt -file whatever.crt -alias localhost
    

    Note the -alias can be whatever unique name you want to use for this cert. The convention is to use the URL of your web site.

    Now, you should be able to load the JKS file with the KeyStore instance in your code. Maybe it’s easier to just change your Java code to use a PKCS12 instance?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I programatically create an NSToolbar in my application. I just added a new button
I would like to programatically convert a Microsoft Word document into XHTML. The language
i have an example of a source code which programatically sets the value of
I'm loading an excel spreadsheet with pivot tables and charts in it into a
In Java I have code that works well on OSX but not in linux.
I am embeding SpiderMonkey (mozila javascript) interpreter/engine in my C/C++ application. i programatically loading
I'm loading a Textbox and a Button into a horizontal StackPanel programmatically. The size
I'm loading a user control programatically like this: protected void Page_Load(object sender, EventArgs e)
I want to programatically create an NSTextView. How can I determine the correct frame
How can I programatically cause a control's tooltip to show in a Winforms app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.