Thursday, 15 July 2010

Detect installed certificate in my android device -



Detect installed certificate in my android device -

i installing certificate in application when application starts. have gone through few of links below , install certificate.

http://nelenkov.blogspot.in/2011/12/ics-trust-store-implementation.html

http://pastebin.com/bn6qsyhx

how programmatically install ca certificate (for eap wifi configuration) in android?

how install ca certificate programmatically on android without user interaction

i came know cannot install certificate silently without user interaction.currently don't know how stop prompt each time user open app.

whenever application starts every time inquire user install certificate. there way can observe whether certificate(in case certificate) installed or not, programmatically.

code snippet have installing certificate in app

private void installcertificate() { seek { bufferedinputstream bis = new bufferedinputstream(getassets().open(my_cert)); byte[] keychain = new byte[bis.available()]; bis.read(keychain); intent installintent = keychain.createinstallintent(); x509certificate x509 = x509certificate.getinstance(keychain); installintent.putextra(keychain.extra_certificate, x509.getencoded()); installintent.putextra(keychain.extra_name, my_cert); startactivityforresult(installintent, install_keychain_code); } grab (ioexception e) { e.printstacktrace(); } grab (certificateexception e) { e.printstacktrace(); } } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == install_keychain_code) { switch (resultcode) { case activity.result_ok: dothetask(); break; case activity.result_canceled: finish(); break; default: super.onactivityresult(requestcode, resultcode, data); } } }

also fyi, installcertificate() called oncreate().

please help me out same. help appreciated.

query: when prompt comes certificate name, entered text comes selected , on orientation alter cut/copy alternative comes. body knows how stop text selection when prompt comes?!!!

i used below piece of code check whether certificate installed or not

try { keystore ks = keystore.getinstance("androidcastore"); if (ks != null) { ks.load(null, null); enumeration aliases = ks.aliases(); while (aliases.hasmoreelements()) { string alias = (string) aliases.nextelement(); java.security.cert.x509certificate cert = (java.security.cert.x509certificate) ks.getcertificate(alias); if (cert.getissuerdn().getname().contains("mycert")) { iscertexist = true; break; } } } } grab (ioexception e) { e.printstacktrace(); } grab (keystoreexception e) { e.printstacktrace(); } grab (nosuchalgorithmexception e) { e.printstacktrace(); } grab (java.security.cert.certificateexception e) { e.printstacktrace(); }

android certificate

No comments:

Post a Comment