如何通过Android API获取该base64公钥?
最佳答案
要获取公共证书,您需要在代码中使用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();
}
关于android - Android-在应用运行时访问自己的公钥?使用哪个 key 对对apk进行签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18250791/