Skip to content

Instantly share code, notes, and snippets.

@prokash-sarkar
Created December 18, 2017 13:52
Show Gist options
  • Save prokash-sarkar/ef3030ec95ded250734b02eaebfd7630 to your computer and use it in GitHub Desktop.
Save prokash-sarkar/ef3030ec95ded250734b02eaebfd7630 to your computer and use it in GitHub Desktop.
A simple code snippet for generating Facebook KeyHash in Android
public void getKeyHash(Context context) {
try {
PackageInfo info = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("Base64", Base64.encodeToString(md.digest(),Base64.NO_WRAP));
}
} catch (PackageManager.NameNotFoundException e) {
Log.d("Name not found", e.getMessage(), e);
} catch (NoSuchAlgorithmException e) {
Log.d("Error", e.getMessage(), e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment