Hi friends i wanna to generate Key hash to incorporate FaceBook Application in my Apps.. I am having Open SSL Zip. pl guide me how to generate key..
-
What is it that you are trying to accomplish? A hash of friends in facebook or an intent to launch facebook from your app? – ahodder Jan 04 '11 at 16:50
-
1I wanna to implement Single Sign On in my apps.. – VenkateshRaghavan Jan 04 '11 at 17:49
-
I am getting this error Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 – Ameer Aug 16 '14 at 13:38
8 Answers
Type this in your terminal (mac)
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Or this into the console (windows)
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
You will have to enter a password. The password is: android
A code will come up and that code is your key hash.

- 12,324
- 20
- 72
- 121
-
This works and it is really simple solution. It takes 2 minutes to implement, 100% recommended! – Freddy Jul 18 '19 at 10:44
-
In order to generate key hash you need to follow some easy steps.
Download Openssl from: http://code.google.com/p/openssl-for-windows/downloads/list
Make a openssl folder in C drive
Extract Zip files into openssl folder
Copy the File debug.keystore from .android folder in my case (C:\Users\SYSTEM.android) and paste into JDK bin Folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin)
Open command prompt and give the path of JDK Bin folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin).
Copy the code and hit enter
keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt
Now you need to enter password, Password = android.
See in openssl Bin folder you will get a file with the name of debug.txt
Now either you can restart command prompt or work with existing command prompt
comes to C drive and give the path of openssl Bin folder
copy the following code and paste openssl sha1 -binary debug.txt > debug_sha.txt
you will get debug_sha.txt in openssl bin folder

- 398,270
- 210
- 566
- 880

- 3,325
- 2
- 15
- 13
-
3i am getting the debug.txt as UUS10U Android10UAndroid Debug0‚0*†H†÷ ‚ 0‚ ‚ °_»‡IÏy%sT³hN—]q¥¤¤{‰‚¾@TìÐàqÍœ¨éÑ”a 0.†@½ÀrVÓ¢>½ðùäëÀ{9‹0z¥iç‡+åsâI” and debug_sha.txt as ~hJ1К¡+eK—§¹7 what could be wrong? – null pointer Mar 06 '13 at 09:52
-
-
I am getting this error, Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 – Ameer Aug 16 '14 at 13:37
-
3My answer should be a comment here. Try `openssl enc -a -e < debug_sha.txt` after the final step – kon psych Dec 18 '14 at 06:50
-
1Please follow my another link http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash/12405323 – Vijay Kumar Dec 19 '14 at 00:25
-
I am Getting Error like in file "keytool error: java.lang.Exception: Keystore file does not exist: debug.keystore"; – Nikhil S Marathe Jun 20 '22 at 12:26
You only need to do this if you want single sign-on. Here's the details though: Key hash for Facebook Android SDK

- 1
- 1

- 2,025
- 19
- 8
- Download and install OpenSSL from http://slproweb.com/products/Win32OpenSSL.html based on windows 32 or 64 bit.(Note: Download and install first visual C++ 208 redisributable from that site also )
- Put the bin directory of installed OpenSSL in windows path.
- Open the command prompt and go to C:\Users{User_Name}.android
- now put this command on cmd "keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64".(refer https://developers.facebook.com/docs/android/getting-started/)
- Now enter password "facebook" without double quote.
- Now a hash key will be generated
- Finally go to the Facebook Developer site. Make sure you are logged into Facebook and, using the dropdown menu in the top-right, go to your 'Developer Settings':
- Once you're in your developer settings, select 'Sample App' from the navigation on the left, and add and save your key hash into your profile:

- 1,128
- 1
- 12
- 21
-
-
-
-
I hope u are on Windows. Go to Computer Properties, Advanced System setting then environment varibales – Pradyumna Swain Aug 16 '14 at 13:46
-
JAVA_HOME is C:\Program Files\Java\jdk1.7.0_45 and ANT_HOME is E:\apache-ant-1.7.1-bin\apache-ant-1.7.1 – Ameer Aug 16 '14 at 13:49
-
1U may find a environment variable JAVA_TOOL_OPTIONS there. Just delete that. – Pradyumna Swain Aug 16 '14 at 13:54
Adding to Vizzz's answer if you want to get the actual key run in openssl bin folder
openssl enc -a -e < debug_sha.txt
I guess the detailed steps are for "debugging" purposes

- 626
- 1
- 11
- 26
-
1I'm sure the answer by Vizzz is incomplete without this extra information. This appears to have given me what I needed. – androidneil Nov 01 '13 at 11:01
-
Although I am glad I helped, I have to admit that I found this information in another site that I don't remember right now and I can't find it either. – kon psych Dec 18 '13 at 14:05
paste this code in onCreate() method.
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.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}

- 773
- 2
- 6
- 23

- 1,206
- 14
- 27
by mistake I just figured out a really simple way to figure out what your key hash is. While setting up a new computer I forgot to generate a keyhash before running the FriendPickerSample from the facebook SDK and I got a message when the sample app opened up on my phone it said. keyhash XXXXXXXX has not been setup by apps developer. From there you can just add the keyhash you see in the XXX to your list and your ready to go.

- 31
- 3
-
I think the asker wants to programmatically generate the hash. – Sir Digby Chicken Caesar Sep 10 '14 at 01:38
I got issues to get Hash key Then I used following steps and win Hash key of android.
1. Download Openssl from: http://code.google.com/p/openssl-for-windows/downloads/list
2. Make a openssl folder in C drive
3. Extract Zip files into openssl folder
4. Copy the File debug.keystore from .android folder in my case
(C:\Users\SYSTEM.android) and paste into JDK bin Folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin)
5. Open command prompt and give the path of JDK Bin folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin).
6. Copy the code and hit enter
7. keytool -exportcert -alias androiddebugkey -keystore debug.keystore >
c:\openssl\bin\debug.txt
Now you need to enter password, Password = android.
8. See in openssl Bin folder you will get a file with the name of debug.txt
9. Now either you can restart command prompt or work with existing command prompt
10. comes to C drive and give the path of openssl Bin folder
11. copy the following code and paste openssl sha1 -binary debug.txt > debug_sha.txt
OR (If Getting Error in file like: "keytool error: java.lang.Exception: Keystore file does not exist: debug.keystore" )
12. Enter full code : keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt | openssl enc -a -e < debug_sha.txt
13. you will get debug_sha.txt in openssl bin folder and also get a key in CMD.

- 599
- 8
- 8