android 获取apk签名的序列号

1.直接从apk上获取

将apk后缀改为zip,用WinRAR打开,将META-INF/CERT.RSA解压出来,比如说解压到D:\CERT.RSA

命令行底下用

D:\android\project>keytool -printcert -file "D:\CERT.RSA"

就能看到序列号了


2.代码中获取

try {
       PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
       try {
            X509Certificate certificate = X509Certificate.getInstance(pi.signatures[0].toByteArray());
           
            BigInteger serialBigInteger = certificate.getSerialNumber();
            Log.i(TAG, "" + serialBigInteger.toString(16));
       } catch (CertificateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
       }
  } catch (NameNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
  }


你可能感兴趣的:(android 获取apk签名的序列号)