Reputation: 9835
I'm new to Java/Android KeyStores, and after reading the documents and some tutorials, I'm still a bit confused as to what the operations do exactly, in particular load and store calls. I'm looking at the following piece of code in a Java method, and have some trouble understanding it. inKeyStore is an input parameter of type KeyStore.
String password = "password";
KeyStore newKeyStore;
FileOutputStream out = mContext.openFileOutput("my.keystore", 0);
FileInputStream in = null;
try {
inKeyStore.store(out, password.toCharArray());
} catch (KeyStoreException e) {
if (out) out.close();
in = mContext.openFileInput("my.keystore");
newKeyStore = KeyStore.getInstance("BKS");
newKeyStore.load(in, password.toCharArray());
if (in) in.close();
}
I know that inKeyStore.store() throws a KeyStoreException if it's uninitialized. However, I'm confused about a few things
Thanks!
Upvotes: 0
Views: 722
Reputation: 697
In your case, you have:
-The KeyStore instance in memory: KeyStore.getInstance(String type, String provider)
-The keystore file on the file system: {app_priv_folder}\my.keystore
To read (file ==> memory): KeyStore:load(InputStream stream, char[] password)
Initializes this KeyStore from the provided InputStream
To Write (memory ==> file): KeyStore:store (OutputStream stream, char[] password)
Writes this KeyStore to the specified OutputStream
Answers:
inKeyStore.store(out, password.toCharArray())
stores the inKeyStore data in the file "my.keystore": FileOutputStream out = mContext.openFileOutput("my.keystore", 0);
Upvotes: 1