First of all, I am new to this encryption operations and I don't know whether my question is proper to ask or not! any solution is appreciated ...
In my project I use this code to create SSLSocketFactory for services:
public static SSLSocketFactory getGlobalSSlFactory() {
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
InputStream caInput = context.getResources().openRawResource(xxxxxxx);
Certificate ca = cf.generateCertificate(caInput);
caInput.close();
KeyStore keyStore = KeyStore.getInstance("BKS");
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(
KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, "xxxxxxx".toCharArray());
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
The error I get when testing on device with android ( Pie ) :
google says: https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html
Important part :
"To resolve this, you should stop specifying a provider and use the default implementation."
How should I change my code ?
** more explanations **
I did what @sonhvp said but after testing that this error comes :
And error come to this line :
Certificate ca = cf.generateCertificate(caInput);
This is my android version :


