Last active
September 11, 2017 08:22
-
-
Save thanhzusu/a8f5f5bf1ab073de66ecb9061c73d814 to your computer and use it in GitHub Desktop.
Android - Get hash key for Facebook app
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
General command: | |
keytool -exportcert -alias [your-key-alias] -keystore [/path/to/your/file.keystore] | openssl sha1 -binary | openssl base64 | |
Example: | |
On OS X, run: | |
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 | |
On Windows, run: | |
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl | |
base64 | |
You can also manually modify the sample code to use the right key hash. For example in HelloFacebookSampleActivity class make a temporary change to the onCreate(): | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// Add code to print out the key hash | |
try { | |
PackageInfo info = getPackageManager().getPackageInfo( | |
"com.facebook.samples.hellofacebook", | |
PackageManager.GET_SIGNATURES); | |
for (Signature signature : info.signatures) { | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); | |
} | |
} catch (NameNotFoundException e) { | |
} catch (NoSuchAlgorithmException e) { | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment