79275586

Date: 2024-12-12 15:05:38
Score: 1.5
Natty:
Report link

Fixed! The trick to using @dave_tompson_085's excellent answer was to get the PrivateKeyEntry in order to get the full private key. In addition, I changed all instances of PEMWriter to JcaPEMWriter.

With that I used the following code to successfully write the private key:

KeyStore.ProtectionParameter protParam =
        new KeyStore.PasswordProtection(secret.toCharArray());
KeyStore.PrivateKeyEntry pkEntry =
        (KeyStore.PrivateKeyEntry) certificate.getEntry(alias, protParam);
PrivateKey key = pkEntry.getPrivateKey();
writer.writeObject(new JcaPKCS8Generator(key, null));
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @dave_tompson_085's
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: ogionnj