I am developing Android app based on native Java. Mobile app working fine with http. But because of several time app got rejected from Google play. So I have to integrate app with https. I successfully hosted backend on HTTPs and consume from PostMan but having issue with integrating https on Android app.

I am getting exception and give up.

java.io.IOException: exception unwrapping private key - java.security.NoSuchAlgorithmException: 1.2.840.113549.1.5.12 SecretKeyFactory not available

Android code:

public static SSLSocketFactory getSocketFactory(Context ctx) {
    try {
        // Get an instance of the Bouncy Castle KeyStore format
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        System.out.println(" KeyStore Load successfully ========");
        // Get the raw resource, which contains the keystore with
        // your trusted certificates (root and any intermediate certs)
        String securityKey =  ctx.getResources().getString(R.string.securitykey);
        System.out.println("===========s Secrete Key " + securityKey);
        InputStream in = ctx.getResources().openRawResource(R.raw.baeldung); 
        System.out.println(" File Read Load successfully ========" );
        System.out.println(" File Read Load successfully ========" + in.available());
        if(in==null){
            System.out.println(" This is empty file");
        }


        try {
            // Initialize the keystore with the provided trusted certificates
            // Provide the password of the keystore
            System.out.println("== keystore is Start load =======");
            keyStore.load(in, securityKey.toCharArray());
            System.out.println("== keystore is compplete load =======");

        }catch(Exception e) {
            e.printStackTrace();
        } finally {
            in.close();
        }
        SSLSocketFactory sf = new SSLSocketFactory(keyStore);
        sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
        return sf;
    } catch (Exception e) {
        e.printStackTrace();
        throw new AssertionError(e);
    }
}

Exception while making connection to Server from App Over Https:

Error logs:

KeyStore Load successfully ========
I/System.out: ===========s Secrete Key Saktiman@121995
I/System.out:  File Read Load successfully ========
I/System.out:  File Read Load successfully ========2748
 I/System.out: == keystore is Start load =======
W/System.err: java.io.IOException: exception unwrapping private key - java.security.NoSuchAlgorithmException: 1.2.840.113549.1.5.12 SecretKeyFactory not available
 W/System.err:     at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.unwrapKey(PKCS12KeyStoreSpi.java:652)
W/System.err:     at com.android.org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(PKCS12KeyStoreSpi.java:891)
 W/System.err:     at java.security.KeyStore.load(KeyStore.java:1544)

KeyStore file is: docmaster.p12

0

There are 0 answers