I´m trying to save a .PFX certificate in to the Internar Storage of my application.
When I get de .pfx from asset or raw the InputStream obtained is good, and works fine. But if I store this InputStream on the Internar Storage (or on Sharedprefences) the .PFX no works...and get this error when load the keystore:
java.io.IOException: stream does not represent a PKCS12 key store
This code works, but I need store the cert on the memory and not get it from assets...:
InputStream is = AppConstants.appContext.getResources().openRawResource(R.raw.XXXX);
This is the code to save the .PFX:
InputStream is = AppConstants.appContext.getResources().openRawResource(R.raw.XXXX);
String filename = "XXXX";
String string = is.toString();
FileOutputStream outputStream;
try {
outputStream = AppConstants.appContext.openFileOutput(filename, AppConstants.appContext.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
This is the code to load the stored .PFX:
String filename = Uri.parse(PFX_FILE).getLastPathSegment();
File file = File.createTempFile(filename, null, AppConstants.appContext.getCacheDir());
keyStore.load(new FileInputStream(file), "xxxx".toCharArray());
How I can save certificates on Internal Memory?