I am writing an Android application. How to use a certificate in httpsinitializing a certificate from a catalog file, and not from packages?
When I have a password file, this code works:
KeyStore keyStore = KeyStore.getInstance ("PKCS12");
keyStore.load (certificateIs, pass.toCharArray ());
KeyManagerFactory kmf = KeyManagerFactory.getInstance (KeyManagerFactory.getDefaultAlgorithm ());
kmf.init (keyStore, pass.toCharArray ());
SSLContext sc = SSLContext.getInstance ("TLS");
sc.init (kmf.getKeyManagers (), trustAllCerts, new java.security.SecureRandom ());
HttpsURLConnection.setDefaultSSLSocketFactory (sc.getSocketFactory ());
But I have a certificate initialized from the der file:
CertificateFactory cf = CertificateFactory.getInstance ("X.509");
X509Certificate certificate = (X509Certificate) cf.generateCertificate (certBytes);
I do not know how to use this certificate through the connection https.
Peter source
share