Question

I am working on an Android app with min API version 10 and target 17. I want to use KeyChain but it is not supported before ICS.

Can someone suggest something similar or a solution for this problem?

Thank you so much

Was it helpful?

Solution

You could use SpongyCastle to create your own KeyStore.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        KeyStore ks = null;
        try {
            ks = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(null,null);

            // Add certs or keys

            ks.store(new FileOutputStream(new File(getFilesDir(),"out.bks")),"password".toCharArray());
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static {
        Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top