2

I'm having trouble loading a .p12 certificate to my Android project. Here is a chunk 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 an error occurred opening cert file.

How can I properly add the cert file to my Android program?

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
amidnikmal
  • 86
  • 3
  • 9

2 Answers2

0

...

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

Community
  • 1
  • 1
CrandellWS
  • 2,708
  • 5
  • 49
  • 111
-1

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() + "");
Harsh Goswami
  • 502
  • 3
  • 12
  • 1
    Where i must place my .p12 certificate? Main problem is that i don't know from what place android read certificate. I use only internal storage, i don't have sdcard. I put .p12 file into Android folder and data folder. I did't find folder of my debugable app on device. – amidnikmal Mar 25 '14 at 11:23
  • 1
    @user3437564 did you find out where to place the certificate? – Feytality Feb 24 '16 at 13:37