查看apk签名 和 keystore 的信息

原文出处:https://www.jianshu.com/p/90b698002215

 

1、keytool -printcert -file ***(把apk文件下的META-
INF文件夹解压出来,得到其中的密钥.RSA文件)

2、keytool -list -v -keystore debug.keystore 查看证书信息

3、给空白包签名 (注意 alias 值)

jarsigner -verbose -keystore [keystorePath] -signedjar [apkOut] [apkIn] [alias]
jarsigner -verbose -keystore debug.keystore -signedjar test2.apk unsign1.apk test

 

4、在应用代码中获取签名信息

public String getSHA1Signature(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo
(context.getPackageName(), PackageManager.GET_SIGNATURES);

byte[] cert = info.signatures[0].toByteArray();

MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] publicKey = md.digest(cert);
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < publicKey.length; i++) {
String appendString = Integer.toHexString(0xFF & publicKey[i])
.toUpperCase(Locale.US);
if (appendString.length() == 1)
hexString.append("0");
hexString.append(appendString);
hexString.append(":");
}
return hexString.toString();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}

 

posted @ 2019-03-11 14:05  LambertL  阅读(1447)  评论(0编辑  收藏  举报