Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 23 September 2014

Android key hash for Facebook App

Official Documentation on facebook developer site:

Its pretty confusing to get a Key hash value for creating Facebook Apps for Android.
Here are the detailed steps for doing that-
1. We need to download openssl from Google code (64 bit users must downloadopenssl-0.9.8e X64, not the latest version) 

2. Extract it. 
create a folder- OpenSSL in C:/ and copy the extracted code here. 

3. Detect debug.keystore file path. 
If we can't find one, then lets do a search in C:/ and we will use the Path in the command in next step. 

4. Detect keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-
> keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

Now, it will ask for password, put android 
That's all. It will return a key-hash.

There is another way to get the key-hash by using these simple lines of code:
try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "your.package.name",
                           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) {

}
Attention: When running an unsigned version you will get the wrong hash key. The version must be signed. Then you can find your key when filtering by tag name: "KeyHash:".

No comments:

Post a Comment