A simple Java key store from a StackOverflow answer to Easy way to store/restore encryption key for decrypting string in java.
I'm a fan of static utility functions and static imports.
import static ch.geekomatic.sjks.KeyStoreUtils.generateKey;
import static ch.geekomatic.sjks.KeyStoreUtils.loadKey;
import static ch.geekomatic.sjks.KeyStoreUtils.saveKey;Generating a key:
SecretKey originalKey = generateKey();Saving a key:
File file = new File("/path/to/key.file");
saveKey(originalKey, file);Loading a key:
File file = new File("/path/to/key.file");
SecretKey persistedKey = loadKey(file);