Saturday, July 14, 2012

Android key hash for Facebook App

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 download openssl-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.

Please post a comment, in case of any issue.


  1. it tells me -exportcert is not recognized as an internal or external command

    1. Hi aggrey,
      instead of just 'keytool' in the command; try with the whole path to the keytool.exe. For e.g-
      > c:/path/to/keytool -exportcert -alias androiddebugkey...

  2. (Sorry if you can't understand me, i dont speak very well)

    Thanks for this, but i have a problem, i can get the h ask key, and i put that in my aplication in facebook developer, but i make the apk and i install in my cellphone, but i can't login whin facebook (i get a FacebookError), can you help me?

  3. Hi! Thanks for exampe.
    But i have a question : where i can get keytool.exe ?

    1. Hi Riddler,
      keytool.exe is in the 'bin/' directory within JRE installation folder.
      Something like- C:\Program Files\Java\jre7\bin

      or simply do a search.

  4. This comment has been removed by the author.

  5. i almost getting all things right but at last step it is surly ask for password for every system..? i have ask for the password as following your steps.....
    please tell me....thanks

    1. Ya. I think, u r putting a wrong commend. Follow these steps then-
      1. Please put the entire command in 1 line.
      2. Regenerate 'debug.keystore' file; by just deleting it. Then a rebuild of the debug package will create a new one. Use that.

    2. Good job,, i'am succes in

  6. Hello ,
    i m following ur step for my app. but still its giving key mismatch error plz help me out.

    1. Hi Gaurav. Check out this post-

  7. hola oye me puedes ayudar es que me marca error en sha1-binary
    me dice que es un comando incalido

  8. Its working and asking for password but not provide me any keyhash. what i am doing wrong here

  9. ... is not recognized as an internal or external commands, operable program or batch files

    1. ...seems you r not in correct keytool.exe directory. You have to go inside that directory and then run the command.

      so before the command, u need to 'cd' to keytool path

      for e.g-

      c:/Users/UserA>cd c:/path/to/keytool/

      c:/path/to/keytool>keytool /?

      ^ it should return command details, here u can run the above command

  10. This comment has been removed by the author.

  11. Thanks man. You saved me a lot of trouble. Keep posting more.

  12. How to get key hash for publishing the application.Please help.

  13. how to get debug.keystore to generate the hash key. Is it the same keystore that we use for phonegap release version?

    I tried generating hash key with that, every time i try to make facebook login with my android device, it says "Invalid android_key parameter, the key *********** does not match any allowed key."

    kindly Help. Thank you

  14. thanks, it helped me in getting hash key.

  15. hello sir,i have tried as per your command mentioned above but it's give me output like.. The system cannot find the path specified. what is wrong with it..

    1. so, there should be a path problem. It couldn't find either keytool or openssl or debug.keystore file. 1. for keytool.exe & openssl, simply search & double check the paths, you needto go into the keytool.exe directory & run commends from there. For e.g-

      c:> cd c:/path/to/keytool
      c:/path/to/keytool> RUN THE COMMAND HERE

  16. hello i have got hash key using this command keytool -exportcert -alias androiddebugkey -keystore "C:\Users\ViralThakar\.android" | openssl sha1 -binary | openssl base64 but it 's not asked me for password and generate key so, it's right key or not.

  17. This comment has been removed by the author.

  18. Hey, maybke I'm very late with my comment, but the keytool didn't ask for a password. Is this normal? I still got a hash key.
    (Sorry 4 my bad english, it's not my mother tongue)

  19. Hey I able to create hash but thank to u, but where do I search for the .keystore file I have to link it to unity3d ty

  20. hi im new to android, i successfully created the hash key and also registered my project in facebook developer page. for first time it works perfectly. but if i again run my app means new hash key is generated and its showing me invalid hash key

    1. does development hash key changes continuosly? how can i manage this scenario. Thank in advance.

    2. let follow the following code to generate key hash
      just replace your pakage name in code with your own pkg name
      public void onCreate(Bundle savedInstanceState) {

      // Add code to print out the key hash
      try {
      PackageInfo info = getPackageManager().getPackageInfo(
      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) {



  21. This comment has been removed by the author.

  22. hai,am enter the fellowing steps but it should not ask any show the hask key value.i am confused is it correct or not???

    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.

    'C:\Users\ADMIN\.android' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\ADMIN>cd C:\Program Files\Java\jdk1.7.0_79\bin

    C:\Program Files\Java\jdk1.7.0_79\bin>keytool -exportcert -alias androiddebugkey
    -keystore "C:\Documents and Settings\Administrator\.android\debug.keystore" | "
    C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

    C:\Program Files\Java\jdk1.7.0_79\bin>

  23. C:\Users\Admin\.android>keytool -exportcert -alias androiddebugkey -keystore "C:
    \Users\\debug.keystore" | "C:\openssl\openssl-0.9.8k_X64\bin\openssl
    " sha1 -binary | "C:\openssl\openssl-0.9.8k_X64\bin\openssl" base64
    The filename, directory name, or volume label syntax is incorrect.

    i face this error how to solve it??

  24. thanks its working. But 1 thing I want to know "Are key hash character vary with the project or these are same for all project in 1 PC ?"