Is there a way to check if an app signature is debug or published?

前端 未结 2 1418
慢半拍i
慢半拍i 2021-02-08 18:23

I am currently developing RPC services for developers to use, but would like to make sure that I can distinguish between another app\'s debug key and their public key. Is there

2条回答
  •  情话喂你
    2021-02-08 18:30

    static final String DEBUGKEY = 
          " key ";    
    
    
    public static boolean signedWithDebugKey(Context context, Class cls) 
    {
        boolean result = false;
        try {
            PackageInfo pinfo = context.getPackageManager().getPackageInfo("your package name",PackageManager.GET_SIGNATURES);
            Signature sigs[] = pinfo.signatures;
    
            Log.d(TAG,sigs[0].toCharsString());
    
            if (DEBUGKEY.equals(sigs[0].toCharsString())) {
                result = true;
                Log.d(TAG,"package has been signed with the debug key");
            } else {
                Log.d(TAG,"package signed with a key other than the debug key");
            }
    
        } catch (android.content.pm.PackageManager.NameNotFoundException e) {
            return false;
        }
    
        return result;
    
    } 
    

    Run this code first time with debugkey, this will alway return false, but you'll get the encoded key in the Logcat. Copy that encoded key, and replace value " key " of DEBUGKEY, and it will work fine.

提交回复
热议问题