28

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

VenkateshRaghavan
  • 291
  • 1
  • 5
  • 5

8 Answers8

44

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.

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
24

In order to generate key hash you need to follow some easy steps.

  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

    keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt
    
  7. 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

  12. you will get debug_sha.txt in openssl bin folder

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Vijay Kumar
  • 3,325
  • 2
  • 15
  • 13
  • 3
    i 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
  • And i am also getting this `å‡×¤Ä¿{ÑŸC kêȃÚÄ – Umer May 09 '14 at 06:00
  • I am getting this error, Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 – Ameer Aug 16 '14 at 13:37
  • 3
    My 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
  • 1
    Please 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
7

You only need to do this if you want single sign-on. Here's the details though: Key hash for Facebook Android SDK

Community
  • 1
  • 1
Daren Robbins
  • 2,025
  • 19
  • 8
5
  1. 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 )
  2. Put the bin directory of installed OpenSSL in windows path.
  3. Open the command prompt and go to C:\Users{User_Name}.android
  4. 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/)
  5. Now enter password "facebook" without double quote.
  6. Now a hash key will be generated enter image description here
  7. 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':
  8. 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: enter image description here
Pradyumna Swain
  • 1,128
  • 1
  • 12
  • 21
4

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

kon psych
  • 626
  • 1
  • 11
  • 26
  • 1
    I'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
1

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();
    }
L.Goyal
  • 773
  • 2
  • 6
  • 23
Mansuu....
  • 1,206
  • 14
  • 27
0

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.

0

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.