0

I have Keystore.jks file and I want to generate public key from it. I have to give the public key file to the other clients who are using my service.

So I generate foo.pem file including public key and private key from Keystore.jks. I run commands from this link

After the foo.pem file generation, I compare two public key and private key with the original keystore.jks file by following coding.

    PrivateKey privateKey = (PrivateKey)keystore.getKey(
                    "testing"
                    , "123456".toCharArray ()
                );

    Certificate l_cert = keystore.getCertificate ("testing");
    PublicKey publicKey = l_cert.getPublicKey();
    System.out.println("Private Key: "+Base64.encodeBase64String(privateKey.getEncoded()));
    System.out.println("Pub key: " + Base64.encodeBase64String(publicKey.getEncoded()));

I would like to know

  • Why two public and private keys are different after generation of foo.pem file?
  • What should I do to get same public and private keys for both files?
Community
  • 1
  • 1
user1156041
  • 2,155
  • 5
  • 24
  • 54
  • Why? What you should be giving them is the *certificate*, by exporting it from the KeyStore. – user207421 Nov 15 '16 at 05:31
  • The only reason is I want to give public key file to clients. So I googling about exporting public key file from keystore jks. I found this answer. I don't know it is suitable or not. – user1156041 Nov 15 '16 at 06:15
  • I asked you *why*? You haven't answered. Restating that you want to do it isn't 'why', or a reason. This is not standard practice. – user207421 Nov 15 '16 at 06:31
  • Where is the second key? I only see one key in your code. – President James K. Polk Nov 15 '16 at 12:22
  • I found that answer to extract public key from pem file. http://stackoverflow.com/questions/10271197/openssl-how-to-extract-public-key Thank u for ur time. – user1156041 Nov 15 '16 at 12:59

0 Answers0