I am trying to import self signed certificate into Keystore. I places cert in asset folder and trying to read inputstream in CertificateFactory.
But CertificateFactory object is null. It is not able to read inputstream. Inputstream is having value I can check that. Please see my code here:
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
AssetManager assetManager = getAssets();
InputStream caInput = assetManager.open("somecert.pem");
X509Certificate caCertificate = (X509Certificate)cf.generateCertificate(caInput);
// Certificate ca = cf.generateCertificate(caInput); //Also did this.
caCertificate is having null value. I am trying to use this in my keystore.
String keyStoreType = KeyStore.getDefaultType();
keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", caCertificate);