Generate key hash in android

Friday, December 30, 2016 Unknown 0 Comments

This is how keyhash is generated in android.



try {
            PackageInfo info = getPackageManager().getPackageInfo("your package name", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();

        } catch (NoSuchAlgorithmException e) {
e.printStackTrace();
        }

0 comments: