Skip to content

Instantly share code, notes, and snippets.

@isfaaghyth
Created July 13, 2017 14:38
Show Gist options
  • Save isfaaghyth/f8c73ac9da82afeb0d8bb7e87002bd98 to your computer and use it in GitHub Desktop.
Save isfaaghyth/f8c73ac9da82afeb0d8bb7e87002bd98 to your computer and use it in GitHub Desktop.
public class KeyHash {
public static void generateKeyHash(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
Log.e("Hash key", something);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment