Last Updated: February 25, 2016
·
2.79K
· leomindez

Generate key hash for Android Facebook Login

When you activate a new app in Facebook for android you will need a key hash. You can use this code fragment for generating the key hash.

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.d("TAG_KEY_HASH", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}

Use ctrl+shift+o to import classes,
then Run the project and you need to find out the TAGKEYHASH in LogCat