【问题标题】:How start an Android application only if there is a specific certificate installed on device?仅当设备上安装了特定证书时,如何启动 Android 应用程序?
【发布时间】:2020-02-25 03:42:07
【问题描述】:

我使用 SAP 移动服务创建了一个混合 Web 应用程序。

此应用程序 (.apk) 必须仅在 Android 设备上安装了特定证书时才能运行。否则,它不应该运行。

有什么办法解决这个问题吗?

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 自己解决了。在 MainActivity.java 中读取设备上安装的所有证书的简单例程。

标签: android security certificate hybrid-mobile-app sap-mobile-services


【解决方案1】:

在 MainActivity.java 中添加这段代码:

boolean isCertExist = false;
        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);

                    System.out.println(cert.getIssuerDN().getName());
                    if (cert.getIssuerDN().getName().contains("<STRING CERT>"))
                    {
                        isCertExist = true;
                        break;
                    }
                }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 2018-11-16
    • 2018-07-17
    • 1970-01-01
    • 2011-08-27
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多