How to add .p12 certificate to android device

2019-02-15 12:08发布

I have trouble with loading .p12 certificate to my android.project. Here is chank of source code:

char[] password = "<my pass>".toCharArray();
FileInputStream fIn = new FileInputStream("<name of cert>");
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(fIn, password);

On line 2 occured error openning cert file.

Can anybody help me. How can i properly to add cert file to my android program?

标签: android ssl
2条回答
Melony?
2楼-- · 2019-02-15 12:46

...

In Android, I see people programmatically install keystore in the following way (The code is from Android developer blog):

byte[] keystore = . . (read from a PKCS#12 keystore)

Intent installIntent = KeyChain.createInstallIntent();
installIntent.putExtra(KeyChain.EXTRA_PKCS12, keystore);
startActivityForResult(installIntent, INSTALL_KEYSTORE_CODE);

I also see people programmatically install only the certificate wrapped inside keystore:

Intent intent = KeyChain.createInstallIntent();
intent.putExtra(KeyChain.EXTRA_CERTIFICATE, cert);
startActivity(intent);

...which leads --@Leem.fin question

may find that the following link a better place to start:

https://developer.android.com/studio/publish/app-signing.html#signing-manually

查看更多
贼婆χ
3楼-- · 2019-02-15 12:56

Try this

File cert = new File("mnt/sdcard/" + filename + ".p12");
InputStream inputStreamFromDownload = null;

keyStore = KeyStore.getInstance("PKCS12");
inputStreamFromDownload = new BufferedInputStream(new FileInputStream(cert));

Log.i("Certificate", inputStreamFromDownload.available() + "");
查看更多
登录 后发表回答