installing ca certificate programatically

Hammad Yaqoob

New member
Dec 9, 2012
1
0
0
Visit site
I am trying to add a CA certificate programatically in a HTC Desire S device Android version 2.3.5 and HTC Sense version 3.0.

I am using the following code:

Intent intent = new Intent("android.credentials.INSTALL");
intent.putExtra("name","testCA");
intent.putExtra("CERT", bytes);
startActivityForResult(intent, CA_CERT_ADDED);

I am populating the variable "bytes" correctly with the certificate bytes. When I run the code the dialog appears stating that I am installing a CA certificate, however the dialog is not populated by the certificate name that I pass in.

On other types of devices (non htc) I do not have this problem. It is only HTC devices.

Has anyone else ever come across this before and is there a solution to it.

Thank you in advance
 

Hikmat Khan

New member
Jul 31, 2013
1
0
0
Visit site
Hi
here comes my code which works perfectly for me.
I am use Commons IO - Download Commons IO apache library to convert CA to byte array.


private void showCAInstallationDialog() {
try {
InputStream caInputStream = getResources()
.openRawResource(R.raw.ca);
if (caInputStream != null) {

byte[] result;

result = IOUtils.toByteArray(caInputStream);

// The next line actually installs the certificate
Intent intent = new Intent("android.credentials.INSTALL");
intent.putExtra("name", getString(R.string.app_name) + " CA ");
intent.putExtra("CERT", result);
startActivityForResult(intent, CA_CERTIFICATE_ADDED);

} else {
Utility.logError(AppName.class.getSimpleName(),
"Error occurred while reading CA");
}
} catch (IOException e) {
e.printStackTrace();
}

}
Commons IO - Download Commons IO