java.security.KeyStore uses KeyStoreSpi implementations to provide keystores of different types. Basic OpenJDK comes with support of JKS, JCEKS and PKCS12 keystore types. The first two implement proprietary Sun/Oracle format and PKCS12 is a public standard.
I know that JCEKS does support symmetric keys and PKCS12 does not. Which other KeyStoreSpi implementations (like Bouncy Castle) provide support of symmetric keys? It looks like devs like to hide such info. E.g. Bouncy Castle docs only mentions:
The fourth is the BCFKS key store which is a FIPS compliant key store which is also designed for general key storage and based on ASN.1. This key store type is encrypted and supports the use of SCRYPT and the storage of some symmetric key types.
Why do you think that a PKCS#12 keystore does not save secret keys in general? I'm working on Desktop OpenJDK 11.x and I do not have any problem in saving and reloading of a secret key with a PKCS#12 keystore.
But you are right - there are some Java implementations where this won't work - just give it a try!
output:
Security warning: the code does not have any exception handling and is for educational purpose only.
code: