I have the following code to generate a KeyStore and save it in the internal memory within the current physical Android device:
try {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
} catch (KeyStoreException e) {
e.printStackTrace();
return;
}
try {
FileInputStream fileInputStream = thisClass_Context.getApplicationContext().openFileInput("Subs2IPA_Crypto.keystore");
} catch (FileNotFoundException e) {
e.printStackTrace();
try {
keyStore.load(null);
FileOutputStream fileOutputStream = thisClass_Context.openFileOutput("Subs2IPA_Crypto.keystore", Context.MODE_PRIVATE);
keyStore.store((KeyStore.LoadStoreParameter) fileOutputStream);
fileOutputStream.close(); ```
I don't know all the details of a cryptographic implementation in Android, and I haven't been able to find a command to provide the default safe or the best FilePath to save the KeyStore. Can you provide such a command or suggest a safe FilePath to save the KeyStore, or even suggest another method to save and obfuscate the storage of the KeyStore file?
The KeyStore must be stored in the internal memory of the physical device, because I need a SecretKey within the KeyStore to decrypt all the time data that were encrypted and saved in a database with that same SecretKey. Without the KeyStore and its SecretKey I cannot read the encrypted database, so the App becomes useless.
And I guess that using a default and automatic FilePath could be safer than actually writing the FilePath in the code.
Gracias (Thanks).