爬取apk的时候,要获取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) { // not using } Certificate[] certs = jarEntry.getCertificates(); if(certs!=null && certs.length>0) { //获取证书 X509Certificate x509cert = (X509Certificate) certs[0]; //获取证书发行者 issuerDN = x509cert.getIssuerDN().toString(); //获取证书所有者 subjectDN = x509cert.getSubjectDN().toString(); //证书key publicKey = x509cert.getPublicKey().toString(); } } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
时间: 2024-10-11 11:20:22