Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I check if two android apps are signed with the same key?

Tags:

java

android

I want to check if signatures of App A and App B are the same.

I want to make the check in App A and call a method based on the result of that comparison.

public boolean compareAppSignatures() {
    Signature[] sigA = getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_SIGNATURES).signatures;
    Signature[] sigB = getPackageManager().getPackageInfo("<App B package name>",PackageManager.GET_SIGNATURES).signatures;
    return Arrays.equals(sigA, sigB);
}

Is this a good way to do it? Also, is there a way to check if they are signed with the same key? Can one android app get the signature list of any other app installed on the device?

like image 674
sr09 Avatar asked Feb 27 '14 03:02

sr09


1 Answers

Yes you can get the signature as follows

PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
Log.i("test", pi.signatures[0].toCharsString());

and correspondingly yo can do as

Signature[] sigA = getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_SIGNATURES).signatures;
    Signature[] sigB = getPackageManager().getPackageInfo("<App B package name>",PackageManager.GET_SIGNATURES).signatures;

than you can compare as follows

public boolean compareAppSignatures() {
    Signature[] sigA = getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_SIGNATURES).signatures;
    Signature[] sigB = getPackageManager().getPackageInfo("<App B package name>",PackageManager.GET_SIGNATURES).signatures;
    return Arrays.equals(sigA, sigB);
}
like image 109
Jitesh Upadhyay Avatar answered Sep 21 '22 11:09

Jitesh Upadhyay