Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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");
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