Self-checking an APK's signature

前端 未结 2 1489
盖世英雄少女心
盖世英雄少女心 2021-01-02 13:45

I would like to programmatically perform a check on the APK\'s signature at runtime. I own a keystore on my development workstation, so I could know (dunno how) the public k

相关标签:
2条回答
  • 2021-01-02 13:53

    I think I have the same situation like you have. Here is my original solution.

    You may have a try on it.

    Signature sig = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
    Signature releaseSig = context.getPackageManager().getPackageAchiveInfo("/mnt/sdcard/myReleaseApk.apk", PackageManager.GET_SIGNATURES).signatures[0];
    return sig.hashCode() == releaseSig.hashCode;
    
    0 讨论(0)
  • 2021-01-02 14:09

    You could try this, it should work

    Signature[] sigs = getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        for (Signature sig : sigs)
        {
            // log the sig here
        }
    
    0 讨论(0)
提交回复
热议问题