Skip to content

Instantly share code, notes, and snippets.

@FabioCZ
Created June 13, 2017 20:08
Show Gist options
  • Save FabioCZ/f77387e3676742203741b1c51baf58c3 to your computer and use it in GitHub Desktop.
Save FabioCZ/f77387e3676742203741b1c51baf58c3 to your computer and use it in GitHub Desktop.
Get hash key in code
public static void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageInfo(pContext, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment