上段代碼:
public static int checkAppSignature(Context context) {
String SIGNATURE = "478yYkKAQF+KST8y4ATKvHkYibo=";//需要固定寫在程序的某個位置的簽名
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
Signature[] signatures = packageInfo.signatures;
Signature sign = signatures[0];
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(sign.toByteArray());
Log.e("proyx", bytesToHexString(md.digest()));
final String currentSignature = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.e("proyx", "Include this string as a value for SIGNATURE:" + currentSignature);
if (SIGNATURE.equals(currentSignature)) {
return 0;
}
} catch (Exception e) {
//assumes an issue in checking signature., but we let the caller decide on what to do.
e.printStackTrace();
}
return 1;
}