Key hash for Facebook Android SDK

58,217

Solution 1

  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#samples)
  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

Solution 2

You can install Open SSL from here , that should make your command work

Solution 3

I created a batch script facebookkeydebug.bat, which return desired Facebook key hash. Just edit the script, set correct paths, keystore name and run it.

:: Getting Android key hash for Facebook app on Windows
:: Requirement: OpenSSL for Windows (http://code.google.com/p/openssl-for-windows/downloads/list)
:: Usage: set paths and run facebookkeydebug.bat

@echo Exporting keystore cert
keytool -exportcert -alias androiddebugkey -keystore C:\Users\myusername\.android\debug.keystore -storepass android -keypass android > debug.keystore.bin

@echo Converting to sha1
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl sha1 -binary debug.keystore.bin > debug.keystore.sha1

@echo Converting to base64
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1 -out debug.keystore.base64

@echo Done, Android hash key for Facebook app is:
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1
@pause

EDIT: I published a repo with some batch scripts for signing and getting cert keys on Windows: https://github.com/petrnohejl/Android-Scripts

Solution 4

you can use code below to get the Hash key :

try {

   PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 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) {
   Log.e("name not found", e.toString());
  } catch (NoSuchAlgorithmException e) {
   Log.e("no such an algorithm", e.toString());
  }

Reference :

http://limbaniandroid.blogspot.com/2013/04/how-to-get-hash-key-for-integarte.html

Solution 5

To make things easier -

keytool.exe -list -alias androiddebugkey -keystore debug.keystore -v

this should provide you with the fingerprints needed, without the hassle of installing openssl.

e.g.

Certificate fingerprints:
         MD5:  1A:5E:AA:CB:1A:CF:68:F0:8B:DA:D8:BC:EE:4F:BF:EE
         SHA1: D2:89:D1:5A:BC:F8:E3:E5:62:4D:DD:20:DD:96:CD:AB:51:A1:C1:7F
         Signature algorithm name: SHA1withRSA
         Version: 3
Share:
58,217

Related videos on Youtube

Anders
Author by

Anders

Novice programmer in any language.

Updated on June 28, 2020

Comments

  • Anders
    Anders almost 4 years

    I can't figure out how to get the Key Hash required to use the Facebook Android SDK. I figured out that I can use keytool with these commands:

      keytool -exportcert -alias [alias]
     -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e
    

    The only problem is that I have no idea where to insert this, I tried through command windows (win7) and I tried opening the file keytool.exe.

  • Anders
    Anders over 13 years
    Allright! I did a stupid mistake, I navigated one folder from where the keytool was. So, I got a lot of jibberish in return and didn't get the opportunity to enter the openssl. Is this also a program I have installed?
  • Falmarri
    Falmarri over 13 years
    Keytool I think is installed with the java jdk. I'm not sure if it's in your path though, I don't work on windows. Also, I'm not sure if openssl is installed by default either. Again, that MIGHT be the linux instructions. Are you sure that's the only thing the document says? It doesn't say what you need to have installed, etc
  • Anders
    Anders over 13 years
    I navigated myself to the keytool file, and the first command worked. But, when using the openssl i got an error stating that the program couldn't be found. The instructions are here: github.com/facebook/facebook-android-sdk/blob/master/README.‌​md under "single sign-on"
  • Anders
    Anders over 13 years
    For others: It is way more simpler if you keep the keytool and OpenSSL files in the same folder.
  • Blundell
    Blundell almost 13 years
    Yeah openssl ISNT installed by default on Windows, facebook sdk tutorial doesn't mention this
  • maephisto
    maephisto over 12 years
    yes, just copy the content of the openssl archive in your jdk1.x.0 folder
  • Paresh Mayani
    Paresh Mayani almost 12 years
    +1 Its working. I am now able to run the command with Openssl.
  • sandyiscool
    sandyiscool over 11 years
    Thanks a lot !! Saved a lot of my time :)
  • Umer
    Umer about 10 years
    but here we needed is Key hash not fingerprints.
  • Mehmed
    Mehmed over 9 years
    This one differs from the key generated by keytool code with password "android". Why?
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me?
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me?
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me?
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me?
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu.
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu.
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu.
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu.
  • Apurva
    Apurva over 8 years
    I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu.
  • Jorgesys
    Jorgesys over 8 years
    Hi @Apurva here is the document developers.facebook.com/docs/android/… , i have updated my answer.
  • Pradyumna Swain
    Pradyumna Swain over 8 years
    Go to facebook Developer site and follow what i wrote
  • Pankaj kumar
    Pankaj kumar over 8 years
    first let me know for what purpose you have generated key hash?
  • Apurva
    Apurva over 8 years
    I want to provide Login using Facebook support in my app and now I have figured out that I need to put that key to facebook developers site. :)
  • Pankaj kumar
    Pankaj kumar over 8 years
    okk, go to developers.facebook.com and register app first then generate keyhash using above code and then paste keyhash
  • Ramiz Ansari
    Ramiz Ansari over 6 years
    use password "android" (without quotes) for debug hash.