Get hash of apk

I'd like my app to compute and show a hash of the app's apk file. It's easily done in Java, but how do I do it for an apk?

The problem is to get a path to the app's apk. In Java

URL url = AutoCheck.class.getResource("Main.class") ;

will find the needed url.

1 answer

  • answered 2018-03-13 20:51 Mathias Ercoreca

    I get the hash code with this code

    private void getHash(){
        try {
            PackageInfo info = getPackageManager().getPackageInfo(YourPackageName, PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                System.out.println("keyhash: " + Base64.encodeToString(md.digest(), Base64.DEFAULT));
        } catch (Exception e) {
            System.out.println("cannot obtain keyhash, " + e.toString());

    Not sure if this is what you need though