如何通过Android API获取base64公钥?
答案 0 :(得分:4)
要获取公共证书,您需要在代码中使用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();
}
答案 1 :(得分:1)
公钥存储在apk内的META-INF / CERT.RSA中。