获取指定已安装完整签名信息,包括MD5指纹:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public void getSingInfo() { try { PackageInfo packageInfo = getPackageManager().getPackageInfo("com.sina.weibo", PackageManager.GET_SIGNATURES); Signature[] signs = packageInfo.signatures; Signature sign = signs[0]; parseSignature(sign.toByteArray()); } catch (Exception e) { e.printStackTrace(); } } public void parseSignature(byte[] signature) { try { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(signature)); String pubKey = cert.getPublicKey().toString(); String signNumber = cert.getSerialNumber().toString(); System.out.println("signName:" + cert.getSigAlgName()); System.out.println("pubKey:" + pubKey); System.out.println("signNumber:" + signNumber); System.out.println("subjectDN:"+cert.getSubjectDN().toString()); } catch (CertificateException e) { e.printStackTrace(); } } |