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

  • Home
  • SEARCH
  • 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 6075761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:31:50+00:00 2026-05-23T10:31:50+00:00

I need asymmetric encryption in java. I generate .key and .crt files with own

  • 0

I need asymmetric encryption in java. I generate .key and .crt files with own password and .crt file by openssl that said in http://www.imacat.idv.tw/tech/sslcerts.html .
How to use these .key and .crt file to extract publickey and private key in Java?

  • 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-23T10:31:50+00:00Added an answer on May 23, 2026 at 10:31 am

    Your .key and .crt files may be in PEM format. To check this open them with a text editor and check whether the content looks like ------BEGIN CERTIFICATE------ (or “begin RSA private key”…). This is generally the default format used by OpenSSL, unless you’ve explicitly specified DER.

    It’s probably not required (see below), but if your certificate is in DER format (a binary format), you can convert them in PEM format using:

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

    (Check the help for openssl rsa for doing something similar with the private key if needed.)

    You then get two options:

    • Build a PKCS#12 file

      openssl pkcs12 -export -in myhost.crt -inkey myhost.key -out myhost.p12
      

    You can then use it directly from Java as a keystore of type “PKCS12”. Most Java applications should allow you to specify a keystore type in addition to the file location. For the default system properties, this is done with javax.net.ssl.keyStoreType (but the application you’re using might not be using this). Otherwise, if you want to load it explicitly, use something like this:

    KeyStore ks = KeyStore.getInstance("PKCS12");
    FileInputStream fis =
        new FileInputStream("/path/to/myhost.p12");
    ks.load(fis, "password".toCharArray()); // There are other ways to read the password.
    fis.close();
    

    (Then, you should be able to iterate through the aliases() of the KeyStore and use getCertificate (and then getPublicKey() for the public key) and getKey().

    • Use BouncyCastle‘s PEMReader.

       FileReader fr = ... // Create a FileReader for myhost.crt
       PEMReader pemReader = new PEMReader(fr);
       X509Certificate cert = (X509Certificate)pemReader.readObject();
       PublicKey pk = cert.getPublicKey();
       // Close reader...
      

    For the private key, you’ll need to implement a PasswordFinder (see link from PEMReader doc) for constructing the PEMReader if the private key is password-protected. (You’ll need to cast the result of readObject() into a Key or PrivateKey.)

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

Sidebar

Related Questions

I need to store sensitive information (a symmetric encryption key that I want to
Imagine for a moment that we're using classic asymmetric encription with WCF (private/public key
There are two keys in asymmetric encryption algorithm public key and private key For
I've been working on a system that uses asymmetric encryption in a large number
I'm new to encryption. I need to implement asymmetric encryption algorithm, which i think
I would like to perform some encryption on client using the asymmetric key stored
I am using openssl. I need to use a bigger RSA key (2048 ).
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL

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.