如何获得APK签名?是否有方法检索用于签署APK的密钥的签名?我用密钥库的钥匙签了我的APK。如何以编程方式检索它?
3 回答
函数式编程
TA贡献1807条经验 获得超9个赞
final PackageManager packageManager = context.getPackageManager();final List<PackageInfo> packageList = packageManager.getInstalledPackages(PackageManager.GET_SIGNATURES);for (PackageInfo p : packageList) { final String strName = p.applicationInfo.loadLabel(packageManager).toString(); final String strVendor = p.packageName; sb.append("<br>" + strName + " / " + strVendor + "<br>"); final Signature[] arrSignatures = p.signatures; for (final Signature sig : arrSignatures) { /* * Get the X.509 certificate. */ final byte[] rawCert = sig.toByteArray(); InputStream certStream = new ByteArrayInputStream(rawCert); try { CertificateFactory certFactory = CertificateFactory.getInstance("X509"); X509Certificate x509Cert = (X509Certificate) certFactory.generateCertificate(certStream); sb.append("Certificate subject: " + x509Cert.getSubjectDN() + "<br>"); sb.append("Certificate issuer: " + x509Cert.getIssuerDN() + "<br>"); sb.append("Certificate serial number: " + x509Cert.getSerialNumber() + "<br>"); sb.append("<br>"); } catch (CertificateException e) { // e.printStackTrace(); } }}
温温酱
TA贡献1752条经验 获得超4个赞
Signature sig = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
Signature releaseSig = context.getPackageManager().getPackageArchiveInfo("/mnt/sdcard/myReleaseApk.apk", PackageManager.GET_SIGNATURES). signatures[0];
return sig.hashCode() == releaseSig.hashCode;
- 3 回答
- 0 关注
- 840 浏览
添加回答
举报
0/150
提交
取消