Create Facebook Hash Key for Android apps
Currently doing a small Facebook client for Android. There are several steps we need to do to get the integration working properly. Here I just give a brief of how to create Hash key to update in Facebook. I did a lot of research to get things working, so thought of writing a post that give the details in one place.
Steps to create Hash Key.
-
Download openssl from Openssl for Windows . I downloaded the Win32 version
-
Unzip and copy all the files in the bin folder including openssl.exe
-
Goto to the folder where you installed JDK for me it’s C:\Program Files\Java\jdk1.6.0_21\bin
-
Paste all the files you copied from Openssl’s bin folder to the Jdk folder.
Now it’s time to run the command to generate the HashKey. You can find more details of Facebook sdk here
keytool -exportcert -alias androiddebugkey -keystore [Key_store_path] | openssl sha1 -binary | openssl enc -a -e
Above command needs the path to your debug keystore. You can find the Keystore path using Eclipse. Goto Window->Preference->Android->Build will open up a window as shown below.
You can find the Default debug keystore. Copy the path and update in our command, now the command will be like
keytool -exportcert -alias androiddebugkey -keystore C:\Users\sarouje\.android\debug.keystore | openssl sha1 -binary | openssl enc -a -e
Fire a command prompt and paste the command and run it. Tool will generate a key for you.
Edit: I was not successful in generating right Key Hash using command prompt or cygWin. My search leads to this post explains how to generate right key for the app. Author also provided the Eclipse project contains the source.
Update Hash Key in Facebook
Goto to your Facebook app page and click Edit settings of your app. Click on the Mobile Native section, page will expand and show the section as shown below
Update the HashKey in the Android Key Hash Textbox and click save changes. We are done, go ahead and run your app and it will work fine. No more Invalid key exception
Edit (Jun-24-2014): Nezzar Waleed notified me about one easy solution he found out in stackoverflow, please check it out as well.
thank you for the post, you can simply add the path of openssl.exe to the PATH environment variable of your PC instead of copying the content
davide cesarini (@davidecesarini)
October 6, 2011 at 7:56 pm
Thanks for your comment Davide. Yes you are right appending the path of openssl to env path will also work fine.
Unfortunately nothing worked for me except using the project provided in the post (http://p-xr.com/implementing-facebook-into-your-app-invalid-key-with-keytool/) to get the key hash.
Sony Arouje
October 6, 2011 at 8:21 pm
Thanks alot for your post.
Anonymous
November 17, 2011 at 6:31 pm
Good to hear that my post helped you. Thanks for leaving the comment.
Sony Arouje
November 18, 2011 at 11:35 am
[…] https://sonyarouje.com/2011/09/18/facebook-hash-key-for-android-apps/ […]
Generate Facebook Hash key for For Android Apps | @ulhack
December 29, 2011 at 9:57 pm
I have used your method, how much time Facebook will take to reflect this change of hash key.
rooban abraham
January 4, 2012 at 11:28 am
It wont take much time, I got it working within 2 or 3 mins
Sony Arouje
January 4, 2012 at 12:26 pm
Great, You save my day. !!
Appreciate your post !! really Helpful
Anonymous
February 1, 2012 at 7:56 pm
Good to hear that my post helped you. Appreciate for leaving the comment.
Sony Arouje
February 2, 2012 at 11:22 am
i got some error while run this command in cmd prompt can anyone suggest me solution how to get run successfully.
Error – openssl is not recognised ….keytool is not recognised
This type of error
jay
March 16, 2012 at 7:01 pm
Please have a look at davide cesarini’s comment and my reply to his comment. Probably that info will solve your issue.
Sony Arouje
March 20, 2012 at 10:59 am
C:\Program Files\Java\jdk1.7.0\bin>keytool -exportcert -alias androiddebugkey -keystore C:\Users\sarouje\.android\debug.keystore | openssl sha1 -binary | openssl enc -a -e it is worked so first find keytool and then insert path thanks for this tutorial!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
chirag
March 21, 2012 at 4:39 pm
i got message “openssl:Error: ‘shal’ is an invalid command.” also asking me for key store password. what to do now?
Nitesh
April 9, 2012 at 4:10 pm
sorry….got it….its sha1 not shal
Nitesh
April 9, 2012 at 4:21 pm
Nitesh, good to know that your issue is solved.
Sony Arouje
April 9, 2012 at 4:47 pm
It’s much easier to modify Util.java from Facebook project and change:
private static boolean ENABLE_LOG = false;
to
private static boolean ENABLE_LOG = true;
Then, when running, you’ll get an error in log, like this one:
Login failed: invalid_key:Android key mismatch. Your key “M76DT4Me9cn2xxxxxxxxxxxxxxxx” does not match the allowed keys specified in your application settings.
Finally go to Facebook and add this hash: “M76DT4Me9cn2xxxxxxxxxxxxxxxx”. Ah, and change back ENABLE_LOG to false.
Jorge
June 13, 2012 at 3:56 am
nice post bro keep it up
shyam
July 9, 2012 at 3:51 pm
Thanks Shyam.
Sony Arouje
July 9, 2012 at 4:04 pm
Please suggest me how to get hash key for facebook app in Mac…
Parent Child
September 25, 2012 at 11:17 am
Are you not getting the key with the way I explained in the post. If not I don’t how to get it, you may need to try it yourself, I never worked in Mac.
Sony Arouje
September 25, 2012 at 11:28 am
thanks a lot …………..
Anonymous
November 26, 2012 at 10:37 pm
You welcome and thanks for leaving your comments.
Sony Arouje
November 27, 2012 at 11:34 am
thanks alot for this post
Anonymous
November 26, 2012 at 10:38 pm
You welcome and thanks for leaving your comments.
Sony Arouje
November 27, 2012 at 11:34 am
its not working actually when i fire command in cmd its showing keytool is not recognized
girish
January 10, 2013 at 1:17 pm
Hi Girish,
Check whether the keytool path is added to the Environment Path. Also check whether the keytool exist in you system. A google search will give you all the details you need.
Regards,
Sony
Sony Arouje
January 10, 2013 at 1:21 pm
Hi Sony, I can’t quite get this to work – do you have any idea what this message could be referring to after I try to execute the command? “Error: Could not determine application home.”
Kind regards,
Connor
Connor
January 11, 2013 at 6:11 am
Hi Connor,
which command you are trying to execute? I never got these kind of error.
Regards,
Sony
Sony Arouje
January 11, 2013 at 10:46 am
I’ve taken a screenshot of the problem here – I hope it’s a simple fix… Additionally, it still generated a key hash after this error (which I’ve greyed out), but the key hash it gives is incorrect.
Thanks,
Connor
Connor
January 11, 2013 at 6:19 pm
Hi Connor,
Can you pls see the last section of this post, there I mentioned an Android code that gives the correct hash key. Even commands didn’t work for me either.
Regards,
Sony Arouje
Sony Arouje
January 14, 2013 at 9:07 pm
hey , its good example. but can you tell me what should be password ? till now i am typing my keystore password. but in some other form i get that it should be only “android” without ” “. & getting http://stackoverflow.com/questions/13894006/android-facebook-sdk-3-0-gives-remote-app-id-does-not-match-stored-id-while-lo same screen in real device not in emulator. please help me.
chintan khetiya
March 15, 2013 at 10:50 am
i got the key… and i’ve added in facebook integration settings…. bt still i got misconfigured err!!!! it’ll work fine in 64 bit but not in 32 bit… do you have any solutions..?
Hiral
April 2, 2013 at 6:00 pm
Hi Hiral,
Not sure what could be the reason for this error. I haven’t looked at this for a long.
Regards,
Sony
Sony Arouje
April 4, 2013 at 2:17 pm
dear anyone help me i got error keytool is not recgonize cammand please help i am stuckoff
fahim
April 9, 2013 at 4:15 pm
Hi Fahim,
Probably you may need to update the path variable or the keytool not exist in your machine.
Regards,
Sony Arouje
Sony Arouje
April 9, 2013 at 4:26 pm
what do you mean update the path i am using this path
C:\Users\M faheem\.android\debug.keystore
fahim
April 9, 2013 at 4:28 pm
Hello!
I generated the key hash for android successfully. But i got key hash in unreadable characters like unicode. So I cant use it in the fb developer settings. What should I do for that?
Anonymous
May 16, 2013 at 11:55 am
Hi,
I am not doing any active development in Android now. I am sorry I may not able to help you out. Did you had a chance to look at the post here http://p-xr.com/implementing-facebook-into-your-app-invalid-key-with-keytool/. I generated the hash key using the method explained in that post.
Regards,
Sony
Sony Arouje
May 16, 2013 at 12:19 pm
Nice tutrial realy helpfull for me
Thanks
Kunal Sharma
January 28, 2014 at 11:42 am
[…] SOURCES:https://sonyarouje.com/2011/09/18/facebook-hash-key-for-android-apps/ , youtube video on hash tag […]
Facebook SDK & Facebook Hash Key for the Android Platform! | gkmaster
June 24, 2014 at 8:17 pm
Thank u! It took me around 3 hours to solve this problem.
The code to get the hash key from MAC is :
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
You can get the key from the app through the following code:
try {
PackageInfo info = getPackageManager().getPackageInfo(
“com.example.kuroi”,
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) {
}
The key will be displayed in the LogCat window.
Rober
November 9, 2014 at 10:50 pm