Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key hash for Facebook Android SDK

People also ask

How do I configure app key hashes on Facebook?

Steps : Go to facebook developer's page : https://developers.facebook.com/ Open the App tabs and than click the Setting. Paste the generate hashkey on HashKey's field = If you don't have it yet, get your key hash part of code.

What is key hash in Android?

You will have to enter a password. The password is: android. A code will come up and that code is your key hash.


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


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


  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

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


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

This is an example of how to get the Key Hash from the Keystore:

first we need to get the paths of:

Java path: C:\Program Files\Java\jdk1.6.0_35\jre\bin

Open SSL Path: C:\OpenSSL-Win32\bin

(install from: http://www.openssl.org/)

Keystore Path: C:\Data\ANDROID\KEYSTORE\

2) then go to Command line and type:

cd [Java path]

3) then type :

keytool.exe -exportcert -alias [alias name] -keystore [Keystore Path]\debug.keystore | [Open SSL Path]\openssl sha1 -binary | [Open SSL Path]\bin\openssl base64

4) the password of your Keystore must be required and then you have the Hash Key related to your Android Keystore.

enter image description here

This is the doc of how to set the Key Hash for Facebook:

https://developers.facebook.com/docs/android/getting-started#release-key-hash


You have to open a command prompt window. Go to start->run and type 'cmd' and hit enter. Then you have to navigate to the folder where keytool is (unless it's in your path), and then type that command.

That is, assuming that command is for windows and not linux.