0

I have two files: rsa-private-key.pem (PKCS#8) and rsa-public-key.pub.

$ cat rsa-private-key.pem

-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----

$ cat rsa-public-key.pub

-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----

Is it possible to create a single Keystore file with both keys? How do I create a single JKS Keystore file including both keys, which I can later use to load and use keys in a Java application?

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
Salvatore
  • 1,145
  • 3
  • 21
  • 42
  • 3
    `KeyStore` is a strange beast. You cannot simply store public or private keys directly. If the public and private key being discussed constitute a matching key pair, then it can be done by creating a self-signed certificate containing the public key, and then storing the private key in the keystore using `setKeyEntry(...)` with the self-signed certificate as the only member of the 1-long chain array. – President James K. Polk Jan 27 '20 at 01:15
  • 1
    Compare https://stackoverflow.com/questions/58753399/how-to-create-a-java-keystore-only-with-a-private-key-file but you have PKCS8-unencrypted privatekey _and_ standard publickey which can be de-PEMed and run thru `KeyFactory.getInstance("RSA")` as `PKCS8EncodedKeySpec` and `X509EncodedKeySpec` respectively. – dave_thompson_085 Jan 27 '20 at 07:34
  • Would you explain me how to do this? – Salvatore Jan 28 '20 at 12:21

0 Answers0