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?