Saturday, May 18, 2013

How to create Facebook Hash key for android apps ?

After a lot of search i found that how to create Facebook hash key for android apps in both modes i.e debug and release modes.

 Steps to create Hash key:

 1. First download oppenssl. click here to download openssl for windows. Download either 32 bit or 64 bit according to your system requirement.
  2. Extract and copy it to your specific location.
 There are two processes to generate Facebook hash-key. one is from command prompt and another via code.

Process 1(Command prompt): 

3. Firstly, open your cmd prompt and change your directory to your java jdk path.

4. Find debug.keystore from your android sdk install path like C:\Users\Teja\.android\debug.keystore. In case of RELEASE MODE key, copy  yourProject.keystore. This one more important to generate your perfect hash key. Otherwise you will get an error like APP MISS_CONFIGURED.

5. And then find your openssl\bin copied & extracted location.

And follow the sample cmd prompt below:

 C:\Program Files\Java\jdk1.7.0_05\bin>keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Teja\.android\debug.keystore" | "C:\Openssl\bin\openssl" sha1 -binary |"C:\Openssl\bin\openssl" base64

6. Run it and provide some password like 'android'. It will generates you hash key like below..

Process 2 (Using method call from android code):

Use below code snippet to get hash key.
public void onCreate(Bundle savedInstanceState) {

    // Add code to print out the key hash

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.sample.facebook",  //Replace your package name here
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {


Save your changes and re-run the sample. Check your log-cat output for a message similar to this:

Note: For release key, run your apk with eclipse then you will get hash key like above.

7. Paste your Facebook Hash key in your Facebook app (
8. Go to Native Android Apps and paste your hash key in there.

Enjoy with your first android  Facebook app..........  

1 comment:

  1. Hi Tej Prakash,
    Thanx. This is very useful when openssl not detect the debug.kyestore from .android in Xp. I was faced this issue in last 2 days. Lot of searched on net, Stack Overflow but not resolved the issue. but after reading your blog, it resolved in few minute. Thank you friend.