java 获取APK签名信息(发行者,所有者)

public static String getAPKSigInfo(String filePath) {
        String subjectDN = "";
        String issuerDN = "";
        String publicKey = "";
        try {
            JarFile JarFile = new JarFile(filePath);
            JarEntry JarEntry = JarFile.getJarEntry("AndroidManifest.xml");
            if (JarEntry != null) {
                byte[] readBuffer = new byte[8192];
                InputStream is = new BufferedInputStream(JarFile.getInputStream(JarEntry));
                while (is.read(readBuffer, 0, readBuffer.length) != -1) {
                    //notusing
                }
                Certificate[] certs = JarEntry.getCertificates();
                if (certs != null && certs.length > 0) {
                    //获取证书
                    X509Certificate x509cert = (X509Certificate) certs[0];
                    //获取证书发行者
                    issuerDN = x509cert.getIssuerDN().toString();
                    System.out.println("发行者:" + issuerDN);
                    //获取证书所有者
                    subjectDN = x509cert.getSubjectDN().toString();
                    System.out.println("所有者:" + subjectDN);
                    //证书key
                    publicKey = x509cert.getPublicKey().toString();
                    System.out.println("publicKey:" + publicKey);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

你可能感兴趣的:(java 获取APK签名信息(发行者,所有者))