46

I'm trying to obtain the key hash for integrating facebook into my Android app. But all over the net I can't find the way to do it on MAC OS X, only for Windows.

If someone could light me with the proper way to obtain the key hash I'd really appreciate it.

Thank you!

Arun G
  • 2,218
  • 1
  • 16
  • 21
ady
  • 525
  • 1
  • 6
  • 8

5 Answers5

172

I used following steps to generate a Key Hash for my app in facebook: (I am using Mac OSX 10.8)

  1. First open a terminal (open a command prompt in windows).
  2. Navigate in the terminal to the directory where your Android debug.keystore is stored.
  3. Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:\Documents and Settings\.android).
  4. Once you are in the “.android” directory, run the following command.

    keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

  5. When it prompts you for a password, type android and hit Enter

  6. Copy the value printed in the terminal that ends with an “=” and paste it in the Key Hash field in Facebook. Then click the Save Changes button.

Reference: Integrate Facebook logins in your Android app

Arun G
  • 2,218
  • 1
  • 16
  • 21
  • Tip: When compiling a `custom.keystore` mind to change the password to the one that you have given when you created the custom.keystore. – Diolor Feb 04 '14 at 22:44
  • 1
    hello Arun, it has been a while since the answer. I just released an android app and it has the facebook login property. So is the key hash taken in your way is the release key hash or can it only be used in developement mode? – saner Jun 09 '16 at 21:54
  • Saner I m sorry for delayed response. I stopped android development for 5yrs. Unable to reply bac – Arun G Jul 10 '17 at 15:08
24

Please follow below steps to find debug.keystore and generate key hash for android development at mac.

  1. Open terminal

  2. Type cd ~/.android and hit enter to go to .android directory

  3. If you want to open .android directory in finder, type open . and hit enter. Then .android directory will be opened in finder where you can find debug.keystore. If you do not want to open .android directory and only want to generate key hash, then skip this point and follow #4.

  4. In terminal where you are already in .android directory type

    keytool -exportcert -alias alias_name -keystore sample_keystore.keystore | openssl sha1 -binary | openssl base64

    and hit enter.

  5. You are asked for password. Enter android as password and hit enter. Then you get key hash ending with "="

  6. Copy key hash,enter in your facebook app setting page and save changes.

Santosh Prasad Sah
  • 1,953
  • 1
  • 15
  • 13
6

Never did it on Mac before, but here are some advices:

1.You need OpenSSL. Install it. In Windows I just extract zip file, then copy three file include openssl.exe in bin folder to jdk's bin folder (where keytool is), don't know how it work on Mac.

2.Copy file keystore what you want to get key hash to jdk's bin folder. My keystore is debug.keystore (because I'm still in test, I don't want to use the main keystore).

3.Using command line to go to jdk's bin folder (In Windows, I just Run -> cmd -> type cd %JAVA_HOME%)

4.Type this command:
keytool -exportcert -alias alias_name -keystore sample_keystore.keystore | openssl sha1 -binary | openssl base64

In my case (debug.keystore):
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
then enter password for debug.keystore: android (without password, the key hash's still generated and the same as with password, don't know why).

You'll get some string with "=" character at the end. Go to your app setting -> mobile -> fill that key hash (include "=") to Android key hash.

Anh Tuan
  • 1,638
  • 1
  • 12
  • 24
  • Linux and Mac store debug.keystore at the same path: ~/.android/debug.keystore. If you want to create new keystore, follow instructions in this link http://developer.android.com/guide/publishing/app-signing.html – Anh Tuan Jul 12 '11 at 13:36
  • You start your answer with _Never do it on Mac_. The user asked specifically for help on Mac OS. You should at least explain why you think he should never do it on Mac (which is not correct by the way, there are no problems generating the keys on Mac) – yacc Sep 03 '15 at 00:16
  • @yacc Sorry for make you misunderstood with my poor English. I mean I never did it on Mac, but I thought the way to generate the keys on Mac is generally the same as on Window, so I gave him the answer. – Anh Tuan Sep 03 '15 at 02:08
  • @AnhTuan You need to specify the actual location. keytool -exportcert -alias androiddebugkey -keystore "%USERPROFILE%\.android\debug.keystore" | C:\openssl\bin\openssl.exe sha1 -binary | C:\openssl\bin\openssl.exe base64 and your install instructions are not clear. Please see http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash the answer with the highest number of votes to coreect – iOSAndroidWindowsMobileAppsDev Jun 23 '16 at 10:39
2

(honestly, not an answer, just a note for all visitors having this or similar trouble)

There is a way to obtain a key hash without JDK and OpenSSL by using pure Java utility android-fb-keytool. You can checkout and build source code.

Dmitry
  • 1,108
  • 13
  • 17
-25

Sorry, what key tool?

If you want to generate a Facebook App ID/Key, go to https://developers.facebook.com/apps and create a Facebook app.

If you want the keytool that you can use to create certificates etc, that is included in the jre.

Explanation for how to deal with the keys and hash here: http://developers.facebook.com/docs/guides/mobile/#android

Stefan H Singer
  • 5,304
  • 2
  • 23
  • 26
  • yeah, thanks :) I figured that out too and edited the post :) – Stefan H Singer Jul 12 '11 at 09:31
  • Sorry, my mistake.I was trying to say that I need the signature of my app so I can integrate facebook in it!The keytool is integrated in jre but I don't know how to use it to generate my app signature for FB! – ady Jul 12 '11 at 09:33
  • I'd daresay they're for Mac only. You have to change them a bit for it to work on Windows, but since you're on Mac you should be fine. – Stefan H Singer Jul 12 '11 at 09:42
  • I'm new to MAC so pls lgiht me a bit:I have to use my terminal and locate my android sdk and at its location execute those commands:D.I know that what I'm asking is foulish but I really don't manage:D.Thank u! – ady Jul 12 '11 at 09:45
  • Yes. You have to use the terminal. If you got specific questions regarding that, that should probably not be on SO since they're not programming questions per se. At least they should be separate questions. Feel free to mark your question as answered and post new questions regarding how to use the terminal on Mac OS X (but probably not on stackoverflow). Good luck! – Stefan H Singer Jul 12 '11 at 09:47