Last active
August 8, 2017 06:02
-
-
Save pranaypatel512/ed6134e864a3533b4faa577d21371e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For SHA: | |
keytool -list -v -keystore '/home/../.android/debug.keystore' -alias androiddebugkey -storepass android -keypass android | |
For Facebook KeyHash: | |
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64 | |
public static String printKeyHash(Activity context) { | |
PackageInfo packageInfo; | |
String key = null; | |
try { | |
//getting application package name, as defined in manifest | |
String packageName = context.getApplicationContext().getPackageName(); | |
//Retriving package info | |
packageInfo = context.getPackageManager().getPackageInfo(packageName, | |
PackageManager.GET_SIGNATURES); | |
Log.e("Package Name=", context.getApplicationContext().getPackageName()); | |
for (android.content.pm.Signature signature : packageInfo.signatures) { | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
key = new String(Base64.encode(md.digest(), 0)); | |
// String key = new String(Base64.encodeBytes(md.digest())); | |
Log.e("Key Hash=", key); | |
} | |
} catch (PackageManager.NameNotFoundException e1) { | |
Log.e("Name not found", e1.toString()); | |
} catch (NoSuchAlgorithmException e) { | |
Log.e("No such an algorithm", e.toString()); | |
} catch (Exception e) { | |
Log.e("Exception", e.toString()); | |
} | |
return key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment