Yes this is a duplicate of this question. The answer to that is, however, wrong and misleading. The answer suggested writing the key to a file where other apps can access the file. If I'm not mistaken, the purpose of keystore is to generate and store private keys that can only be seen by your app, so I'm not even sure why the answer was accepted in that question.
Another question is about encryption and decryption but not really about saving the data to keystore.
Another one here might be what I'm looking for but if I'm not mistaken, CipherOutputStream
is similar to FileOutputStream
but it encrypts the data first before writing it. From the docs:
This class wraps an output stream and a cipher so that write methods send the data through the cipher before writing them to the underlying output stream.
What I want to know here is not the one generated using keytool (I'm guessing it is different, unless I'm wrong) but the one introduced in android 4.3. Either way, I want to learn to save private keys in keystore programmatically.
Aditional Info
Ok, so I found that you can automatically generate keys once you call the KeyPairGenerator
as demonstrated in this app. But what I want to do is generate a key in my server (as my app is offline and will occasionally connect online), then save that key inside keystore as an entry. My problem now is creating entry then saving it. The reason for this is, I want to create one key like an api key for my app. If I use the key generated by keystore, it would have been different everytime I create it for different devices.