Search code examples
securitykeystore

Append Entry To KeystoreFile


I have an keystore file with AES 256 keys and I would like to increase it. I have the following code:

final KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE);
ks.load(inputStream, ksPassword);
ks.setEntry(entryName, new KeyStore.SecretKeyEntry(appKey), entryPassword);
ks.store(new FileOutputStream(outputStream, true));

But when I call the store method the new key entry isn't stored on a existing file referenced by my outputStream. Any ideas? Is possible to increment keys on existing keystore file?


Solution

  • I found the solution! When I created the outputStream I created using the StandardOpenOption.APPEND. I changed to StandardOpenOption.TRUNCATE_EXISTING and that works!

    Thanks!