I am successfully loading and using an PKCS12 file Cert.pfx from Assets like this:
String certLocation = "certificates/Cert.pfx";
InputStream isCert = null;
try {
isCert = getAssets().open(certLocation);
} catch (Exception e) {
Log.d(TAG, "Could not get Assets");
}
// Work with the certificate
I am trying to do the same now, but reading from a storage in Android.
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/PrintableRSA");
File cert = new File(dir,"Cert.pfx");
InputStream isCert= null;
try {
isCert = new BufferedInputStream(new FileInputStream(cert));
isCert.close();
Log.d(TAG,"Sucsess!");
} catch (Exception e) {
Log.d(TAG, "Could not load the file");
}
// Same work with the certificate
The file loads sucsessfully, but When I further to work with isCert InputStream, loaded from storage, it does not work. I suspect that therefore the files are not equal.
I also tried with InputStream isCert = FileInputStream(cert);
unsuccessfully.
How can I fix this issue?