2

如何通过 Android API 获取 base64 公钥?

4

2 回答 2

5

要获取您的公共证书,您需要PackageManager在代码中使用:

PackageInfo packageInfo = null;

try {
   packageInfo = getPackageManager().getPackageInfo(getPackageName(), 
                                           PackageManager.GET_SIGNATURES);

   Signature[] signatures = packageInfo.signatures;
   byte[] cert = signatures[0].toByteArray();
   InputStream input = new ByteArrayInputStream(cert);

   CertificateFactory cf = CertificateFactory.getInstance("X509");
   X509Certificate c = (X509Certificate)cf.generateCertificate(input);

   PublicKey key = c.getPublicKey();

   ...   

} catch ( Exception e) {
        e.printStackTrace();
}
于 2013-08-15T14:32:36.590 回答
1

公钥存储在 apk 内的 META-INF/CERT.RSA 中。

于 2013-08-15T10:30:49.143 回答