Detect installed certificate in my android device(在我的 android 设备中检测已安装的证书)
问题描述
当应用程序启动时,我正在我的应用程序中安装证书.我浏览了以下几个链接并成功安装了证书.
I am installing a certificate in my application when application starts. I have gone through few of the links as below and successfully install the certificate.
http://nelenkov.blogspot.在/2011/12/ics-trust-store-implementation.html
http://pastebin.com/Bn6qSYHx
如何以编程方式在 Android 中安装 CA 证书(用于 EAP WiFi 配置)?
如何安装 CA在 Android 上以编程方式获得证书,无需用户交互
我知道我们无法在没有用户交互的情况下静默安装证书.目前我不知道每次用户打开我的应用时如何停止提示.
I came to know we cannot install the certificate silently without user interaction.Currently I don't know how to stop prompt each time user open my app.
每当我的应用程序当前每次要求用户安装证书时启动.有什么方法可以检测证书(在这种情况下是我的证书)是否已经安装,以编程方式.
Whenever my application starts currently every time it ask user to install certificate. Is there some way I can detect whether a certificate(in this case my certificate) is already installed or not, programmatically.
我在我的应用中安装证书的代码片段
Code snippet where I have installing certificate in my app
private void installCertificate()
{
try
{
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);
}
catch (IOException e) {
e.printStackTrace();
}
catch (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);
}
}
}
另外仅供参考,installCertificate() 是从 onCreate() 调用的.
Also FYI, installCertificate() is called from onCreate().
请帮助我.任何帮助将不胜感激.
Please help me out for the same. Any help will appreciated.
查询: 当提示输入证书名称时,输入的文本将作为选中状态出现,并在方向更改时出现剪切/复制选项.任何人都知道如何在提示出现时停止文本选择?!!!
Query: When prompt comes for certificate name, entered text comes as selected and on orientation change cut/copy option comes. Any body knows how to stop text selection when prompt comes?!!!
推荐答案
我使用下面这段Java代码来检查我的证书是否安装:
I used the below piece of Java code to check whether or not my certificate is installed:
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;
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (java.security.cert.CertificateException e) {
e.printStackTrace();
}
这篇关于在我的 android 设备中检测已安装的证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在我的 android 设备中检测已安装的证书


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01