By ravi babu

2010-12-08 15:08:53 8 Comments

I'm working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the (text file) in there, in which it is mentioned to generate the key hash for Android. How do I generate it?


@priyanga 2018-12-19 08:40:50

For Windows:-

1.Download openssl(openssl-for-windows)
2.Copy and Paste openssl folder into c drive.
3.C:\Android\.android\debug.keystore => Debug Keystore path
4.C:\Program Files\Java\jdk1.8.0_181 => JDK PATH
5.Go to jdkpath=>Enter the below command. (keytool inside Debug keystore path)  

keytool -exportcert -alias androiddebugkey -keystore C:\ \debug.keystore |"C:\openSSL\bin\openssl" sha1 -binary | "C:\openSSL\bin \openssl" base64

@Prashant Jajal 2018-01-19 10:40:00

Use this for print key hash in kotlin

try {
        val info = context.getPackageManager().getPackageInfo(context.packageName,
        for (signature in info.signatures) {
            val md = MessageDigest.getInstance("SHA")
            Log.d("Key hash ", android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT))
    }catch (e:Exception){


@Bassem Samy 2012-03-07 11:30:10

You can use this code in any activity. It will log the hashkey in the logcat, which is the debug key. This is easy, and it's a relief than using SSL.

PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        String something = new String(Base64.encode(md.digest(), 0));
        //String something = new String(Base64.encodeBytes(md.digest()));
        Log.e("hash key", something);
} catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());

You can delete the code after knowing the key ;)

@Bassem Samy 2013-04-22 13:48:41

Guys, take care, after creating the apk, the key hash is changed! because using this code u get the debug keystore hash, but when creating apk, it's another hash, gotta capture it from log after trying ur apk on emulator , then delete code and export again without this log :) - i know it's a hassle :D but for me it was easier than keytool, good luck ;)

@AnhSirk Dasarp 2013-09-05 05:35:24

Opensssl always creating issues. This method is the best one. Just create a blank app , and get the key printed, Use it. Thanks man!!

@Chris Cirefice 2015-08-15 17:32:14

This is by far the easiest solution. Using the keytool command I was getting the wrong key hashes (I have no idea why, decided I didn't care enough to investigate). This worked and literally took 5 minutes to get the debug and release key hashes. +1

@Sébastien 2016-12-09 15:57:40

Is this supposed to work to get a Release hash? (when running inside an APK signed with release keystore, of course).

@Bassem Samy 2016-12-10 20:36:04

Yes Sebastien, you just need to install the signed apk on a device connect it to android studio and check the log cat, or u can show the hash in an edittext in the ui and copy it, anyway yes the hash this code produces works with the signed apk :)

@Naeem Ibrahim 2017-01-20 12:14:35

Generate HashKey for debug and release mode by using this.…

@Tabish 2018-03-28 17:48:44

using keytool is such a mess this is really simple

@Muhammad Omar ElShourbagy 2017-09-10 06:09:06

As answered on a similar issue i found this to be working for me:

  • Copy the apkname.apk file you want to know the hash of to the 'Java\jdk1.7.0_79\bin' folder
  • Run this command keytool -list -printcert -jarfile apkname.apk
  • Copy the SHA1 value and convert it using this site
  • Use the converted Keyhash value (ex. zaHqo1xcaPv6CmvlWnJk3SaNRIQ=)

@Ilya Gazman 2013-01-15 06:27:41

Add this code to onCreate of your activity, it will print the hash under the KeyHash tag in your logCat

try {
    PackageInfo info = getPackageManager().getPackageInfo(
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
catch (NameNotFoundException e) {

catch (NoSuchAlgorithmException e) {


You can add multiple hashkeys for your account, so if you been running in debug don't forget to run this again in release mode.

@derogab 2015-10-09 18:07:40

Excellent Code!

@benleung 2016-02-13 17:56:33

great solution, I guess there should be no executable unsigned version? unsigned version should be unable to install on any device. Those debug version are signed with debug keystore :)

@Raj Bedi 2019-04-26 11:48:12

Best solution. None of the above working for me

@Ashana.Jackol 2016-09-27 07:18:58

  • download openSSL for windows in here you can find 64bit and 32bit here

  • extract the downloaded file

  • create folder name openSSL in C drive
  • copy all the extracted items in to openSSL folder (bin,include,lib,openssl.cnf)
  • get android debug keystore, default location will be


  • now get your command prompt and paste this code

keytool -exportcert -alias androiddebugkey -keystore C:\Users\\debug.keystore | "C:\openSSL\bin\openssl" sha1 -binary | "C:\openSSL\bin\openssl" base64

  • hit enter and you will get the 28 digit keycode

@sud007 2016-12-02 18:15:26

NO it asks for password. typing android gives a 24 digit hash and typing a gives 28 digit hash. No idea why!

@KawaiKx 2017-04-25 19:02:56

bad links! they don't have keytool at all

@Ashana.Jackol 2017-10-11 08:27:47

Link works perfectly bro still you can download it from there...

@Hiren Patel 2015-10-07 11:01:40

I have done by this way for Linux OS & Windows OS:


  • Download Openssl
  • Open terminal
  • keytool -exportcert -alias **myaliasname** -keystore **/home/comp-1/Desktop/mykeystore.jks** | openssl sha1 -binary | openssl base64

Kindly change Alias Name and Keystore with it's path as your requirement.

Terminal would ask for Password of Keystore. You have to provide password for the same Keystore.

So finally you would get the Release Hashkey.


Steps for Release Hashkey:

  • Download Openssl (Download from here), I have downloaded for 64 bit OS, you can find more here
  • Extract downloaded zip file to C:\ drive only
  • Open command prompt
  • keytool -exportcert -alias **myaliasname** -keystore **"C:\Users\hiren.patel\Desktop\mykeystore.jks"** | "C:\openssl-0.9.8e_X64\bin\openssl.exe" sha1 -binary | "C:\openssl-0.9.8e_X64\bin\openssl.exe" base64

Kindly change Alias Name and Keystore with it's path as your requirement.


Please put your details where I have marked between ** **.

Terminal would ask for Password of Keystore. You have to provide password for the same Keystore.

So finally you would get the Release Hashkey.


@Akash Bisariya 2016-12-21 10:07:48

what is the password here?

@Hiren Patel 2016-12-21 10:13:25

@AkashBisariya, password of keystore, that you have given while creating the keystore.

@Akash Bisariya 2016-12-21 14:15:00

thanks @Hiren Patel

@Anand Phadke 2018-11-28 06:44:46

Where I can find the key after successfully generated?

@Hiren Patel 2018-11-28 11:33:09

In terminal / command prompt.

@SANJAY GUPTA 2016-03-03 07:58:29

Use this command after keep open ssl in c drive and in openssl folder.

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\AJAY\debug.keystore" | openssl sha1 -binary | openssl base64

@mohit sharma 2016-02-18 05:31:00

  1. Simply Open you Main Activity File and create below mention function:

         try {
        PackageInfo info = getPackageManager().getPackageInfo(
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {

1.1 Run you Application, this will generate a Hash key for your application.

  1. Now, Open log cat and search with "KeyHash" and copy the hash key.

  2. One you generate the Hash key you can remove this function.

@Undra Bailey 2015-06-29 06:48:51

For people who dont know how to code, AivarsDa's key gen tool on google play i the easiest solution. just get the hash key from it and copy to the facebook app settings. The share on the keygen tool makes my app crash on my phone, so i just manually typed it in notepad and copied it to fb. Finally past this step after days of frustration

@Maniya Joe 2013-10-07 11:54:58

Download openSSL -> Install it -> it would usually install in C:\OpenSSL

then open cmd and type

cd../../Program Files (Enter)

java (Enter)

dir (Enter)

cd jdk1.6.0_17 (varies with jdk versions) (Enter)

to check jdk version go to C:/program files/java/jdk_version

cd bin (enter)

keytool -exportcert -alias androiddebugkey -keystore C:Users\Shalini\.android\debug.keystore | "C:\OpenSSL\bin\openssl sha1 -binary | "C:\OpenSSL\bin\openssl base64 (Enter)

It will ask you for password which is android.

@HTML5 developer 2015-03-11 09:29:34

To generate a hash of your release key, run the following command on Mac or Windows substituting your release key alias and the path to your keystore.

On Windows, use:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

This command should generate a 28 characher string. Remember that COPY and PASTE this Release Key Hash into your Facebook App ID's Android settings.


Refer from : and

@Singed 2015-02-25 17:23:12

The simplest solution:

  1. Don't add the hash key, implement everything else
  2. When facebook login is pressed, you will get an error saying "Invalid key hash. The key hash "xxx" does not match any stored key. ..."
  3. Open the facebook app dashboard and add the hash "xxx=" ("xxx" hash from the error + "=" sign)

@Shahar 2013-07-18 19:38:49

I've created a small tool for Windows and Mac OS X. Just throw in the key-store file, and get the hash key.

If you want the default debug.keystore file, use the default alias and password. Else, use your own keystore file and values.

Check it out, download the Windows version or download the Mac OS X version (Dev-Host might be down sometimes... so if the link is broken, PM me and I'll fix it).

I hope that help you guys...

Dec 31, 2014 - EDIT: Changed host to AFH. Please let me know if the links are broken

Nov 21, 2013 - EDIT:

As users requested, I added a default keystore location and a DONATE button. Feel free to use it if I've helped you. :)

Screen shot Screen shot 2

@Morten Holmgaard 2013-10-15 17:29:12

Default path to debug.keystore: C:\Users\username\.android\debug.keystore

@Morten Holmgaard 2013-10-15 17:37:48

So easy! Both dev and production hash keys - Thanks..

@Shahar 2013-10-26 23:58:19

@MortenHolmgaard , I will try to add it in the near future, Tx for your comment.

@Arslan 2013-11-06 05:22:53

The best one I found

@Adam Varhegyi 2013-11-08 12:14:19

Best. Method. Ever. Where is the donate button ?

@Shahar 2013-11-12 10:29:48

@AdamVarhegyi - Thanks, will add one in next version :)

@Anearion 2014-01-07 10:13:52

Hi, i'm trying to use your tool but it gives me an "Missing Keystroke file" error also if i dragged the keystore into it and the path is 100% correct.

@Shahar 2014-01-07 10:52:58

@Anearion i dont know this error but i'd love to debug it. can you please add info? Windows version, the path you are using, try running as admin maybe.

@Anearion 2014-01-07 16:53:34

@Shahar2k5 Don't know really, started again and worked like a charm. Sorry

@Vinayak 2014-04-14 06:04:34

Works like a charm! Thanks for sharing :)

@MajorGeek 2014-12-01 05:12:23

Its detected as Virus.whats the reason?

@Shahar 2014-12-02 20:12:53

@MajorGeek can you please add a link to a screenshot? so i can see whats the issue. there shouldn't be any thing related to virus...

@MajorGeek 2014-12-03 10:23:49

Here is the link. My antivirus pops up as soon as the download is complete. The extension is facebookh2ko.exe.exe

@Jack 2014-12-09 18:42:19

@ShaharBarsheshetWhen I try and download this tool It installs a download manager instead of the tool?

@Shahar 2014-12-10 10:48:30

@MajorGeek and Jack i assume you downloaded the using the AD button and not the real download,. please check that the download link contains the DevHost domain name "" check the image for more details. please update if that solved your issues.

@MajorGeek 2014-12-10 15:40:46

@Shahar Barsheshet Thank you. you are right. Downloaded from Devhost domain and no issue faced.

@Nicklas Møller Jepsen 2014-12-31 12:22:35

@ShaharBarsheshet Please keep a decent tone. The fact that you need to guide other people to which button they need to click to be able to download your program should cause your answer to be deleted. I know how to download your program, I just downvote your answer, simply to help avoid other people from going to the malicious website you linked to.

@harikrishnan 2015-08-06 07:35:16

now am using android studio.. above tool will able to use ?

@Shahar 2015-08-06 11:35:53

@harikrishnan sure! you just need the keystore file

@Omar Faroque Anik 2015-09-17 14:41:30

It creates wrong release key hash for me unfortunately

@Shahar 2015-10-03 16:42:34

@MdOmarFaroqueAnik i don't think that's possible, are you sure you are using the right file and the correct password and alias?

@wesley franks 2015-12-13 02:23:28

@ Shahar hey I tried this and for some god awful reason my key was empty?

@nightfixed 2015-12-20 19:01:02

I don't understand something: why is your tool giving different SHA key, compared to using the keytool command line? Isn't it supposed to produce identical results, if applied to the same keystore file?

@Shahar 2015-12-21 04:24:36

it should, and it is. are you sure you are using the same keystore file for both?

@Naeem Ibrahim 2017-01-20 12:14:43

Generate HashKey for debug and release mode by using this.…

@CodeMonkey 2017-03-09 22:20:03

Enjoy that beer friend.

@vlatkozelka 2017-05-04 06:33:46

We put our alias and password in this tool. Which means this can easily be sending this stuff to this tools owner- Imagine a large database of keystores + passwords -. Of course nothing is forcing anyone to use it...

@Shahar 2017-05-04 09:15:08

@vlatkozelka, check the source my friend

@Erich García 2017-10-10 17:30:41

Yes, great tool! @Shahar

@Ramkailash 2014-07-24 05:10:19

For an Android application

This code is used to get the hash key in your Android application for Facebook integration. I have tested all devices and it's working. Only change the package name of this code:

private void facebookHashKey() {

    try {
        PackageInfo info = getPackageManager().getPackageInfo("", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            String hashCode  = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            System.out.println("Print the hashKey for Facebook :"+hashCode);
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {


@Pravin Mohol 2013-08-27 09:50:15

I did a small mistake that should be kept in mind. If you are using your keystore then give your alias name, not androiddebugkey...

I solved my problem. Now if Facebook is there installed in my device, then still my app is getting data on the Facebook login integration. Just only care about your hash key.

Please see below.

C:\Program Files\Java\jdk1.6.0_45\bin>keytool -exportcert -alias here your alias name  -keystore "G:\yourkeystorename.keystore" |"G:\ssl\bin\openssl" sha1 -binary | "G:\ssl\bin\openssl" base64

Then press Enter - it will ask you for the password and then enter your keystore password, not Android.


@noelyahan 2012-07-15 17:14:35

To get the Android key hash code, follow these steps:

  1. Download OpenSSL for Windows here
  2. Now unzip to the C drive
  3. Open a CMD prompt
  4. Type cd C:\Program Files\Java\jdk1.6.0_26\bin
  5. Then type only keytool -export -alias myAlias -keystore C:\Users\your user name\.android\myKeyStore | C:\openssl-0.9.8k_WIN32\bin\openssl sha1 -binary | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e
  6. Done

@Palani Kumar 2012-09-24 09:26:58

Great Answer. Thank you very much.

@IgorGanapolsky 2012-11-20 04:44:36

Is this for debug key or for release key?

@Pallavi 2013-01-10 14:01:01

@IgorGanapolsky instead of path of myKeyStore, give the path of your release key. The above code is for debug key

@AB1209 2013-02-21 10:40:05

Really Great Answer.

@Ron 2012-04-24 06:25:34

The simplest solution I have found is this:

  • Open up Log Cat
  • Try and access Facebook with the Android SDK
  • Look for the line in the log that looks like this:

    04-24 01:14:08.605: I/System.out(31395): invalid_key:Android key mismatch. 
    Your key "abcdefgHIJKLMN+OPqrstuvwzyz" does not match the allowed keys specified in your
    application settings. Check your application settings at
  • Copy "abcdefgHIJKLMN+OPqrstuvwzyz" and paste it into the Facebook Android Key Hash area.

@afenkner 2018-01-13 06:26:08

Super simple, thank you!

@DeltaCap019 2012-03-19 07:22:26

This is what is given at the official page of Facebook:

   keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Let me break this command into fragments.

  1. Look for "keytool.exe". You can search that on the C: drive. You can find it in "java jdk" or "java jre". If you have installed multiple versions, choose any.

  2. Open a CMD prompt and go to the above directory where you found "keytool.exe".

    Clip the "exe`" and paste the above command provided on the Facebook page.

  3. You will get an error on entering this that OpenSSL is not recognized as in input output command. Solution : Download "Openssl" from OpenSSL (if you have a 64-bit machine you must download openssl-0.9.8e X64). Extract and save it anywhere... I saved it on the C: drive in the OpenSSl folder

  4. Replace the openssl in the above command in which you was getting an error of OpenSSL with "C:\OpenSSL\bin\openssl" at both the places after the pipe, "|".

  5. If prompted for a password, enter android.

And you will get your hash key. For further steps, refer again to the Facebook page.

@AivarsDa 2014-07-20 09:00:35

The best approach is to use the following code:

private void getHashKey(String pkgName)
        PackageInfo info = getPackageManager().getPackageInfo(pkgName, PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures)
            MessageDigest md = MessageDigest.getInstance("SHA");
            String hashKey = Base64.encodeBytes(md.digest());
            Log.i("KeyTool", pkgName + " -> hashKey = " + hashKey);
    catch (NameNotFoundException e)
    catch (NoSuchAlgorithmException e)

But I was so frustrating with the fact that there is no simple tool to generate the HashKey for the Facebook app. Each time I had to play with Openssl and Keytool or to use a code to get the hash from signature ...

So I wrote a simple KeyGenTool that will do that work for you: -> KeyGenTool on Google Play <-

Enjoy :)

@Biraj Zalavadia 2013-08-07 10:52:34

For Linux

Open Terminal :

For Debug Build

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

you wil find debug.keystore from ".android" folder copy it from and paste on desktop and run above command

For release Build

keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64

NOTE : Make sure In Both case it must ask for password. If it does not asks for password that means something is wrong in command.

@Javal Nanda 2013-09-26 12:21:45

I am getting different values with different alias name, how to verify which one is correct?

@Biraj Zalavadia 2013-09-26 12:23:11

it it asking for password with both the alias name ?

@Javal Nanda 2013-09-26 12:30:40

ya and whatever password I enter it is given me the hash key.. my app is already on play store and native fb is not working now. I will need to anyhow generate exact key hash for release build. Developers are suggesting to include code inside the onCreate in following post , but i want to make it work without app update on playstore…

@Biraj Zalavadia 2013-09-26 12:36:53

yes there is a problem with widows with openssl. You can achieve with code specified in that post.

@Biraj Zalavadia 2013-09-26 12:41:00

If you want do without update on playstore. 1) Create New android Demp app. 2) Put that piece of code in on create. 3) sign this demo app with the same keystore of you app on app store 4) Then Run this signed apk 5) And use this hash key finally

@Harsha 2016-11-09 09:46:14

for debug and release purposes we generate two hash keys but am integrated in facebook developer site and posted in play store and download from store and login with facebook showing invalid hash key

@Biraj Zalavadia 2016-11-09 09:55:46

Simple way to resolve. You will display HashKey on screen. Just type that key on App settings facebook developer console.

@Jamshid 2013-07-13 11:14:18

Firstly, to generate your key hash on your local computer, run Java's keytool utility (which should be on your console's path) against the Android debug keystore. This is, by default, in your home .android directory).

on ubuntu, it's woking in my computer

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

@Pijusn 2013-08-05 20:47:25

Password: android

@Pravin Mohol 2013-05-13 06:49:34

keytool -exportcert -alias androiddebugkey -keystore       C:\Users\pravin\.android\debug.keystore | "H:\OpenSSL\bin\openssl" sha1 -binary | "H:\OpenSSL\bin\openssl" base64

This worked for me ...


1) Open command line go to - > java Keytool..... for me C:\Program Files\Java\JDK1.7\bin
2) Download OpenSSL from google
3) paste this with changing your paths -
   keytool -exportcert -alias androiddebugkey -keystore C:\Users\pravin\.android\debug.keystore | "H:\OpenSSL\bin\openssl" sha1 -binary | "H:\OpenSSL\bin\openssl" base64 

    ....................   give proper debug.keystore path and openSSL path .. 

4) Finley it may be ask u password .. so give password -> android   ...
5) you will get 28 characters that will be your has key

@Anil Bhatiya 2013-07-03 09:30:05


import android.os.Bundle;
import android.text.Editable;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

    Button btn;
    EditText et;
    PackageInfo info;
    protected void onCreate(Bundle savedInstanceState) {
        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {
                    info = getPackageManager().getPackageInfo("", PackageManager.GET_SIGNATURES);
                    for (Signature signature : info.signatures) {
                        MessageDigest md;
                        md = MessageDigest.getInstance("SHA");
                        String something = new String(Base64.encode(md.digest(), 0));
                        //String something = new String(Base64.encodeBytes(md.digest()));
                        et.setText("" + something);
                        Log.e("hash key", something);
                } catch (NameNotFoundException e1) {
                    Log.e("name not found", e1.toString());
                } catch (NoSuchAlgorithmException e) {
                    Log.e("no such an algorithm", e.toString());
                } catch (Exception e) {
                    Log.e("exception", e.toString());


@Loolooii 2015-09-07 20:16:42

This code does not generate a valid hash key for me. @Jamshid's answer works for me on Mac OSX.

@Hardik Thaker 2013-03-28 10:17:57

Official Documentation on facebook developer site:

public void onCreate(Bundle savedInstanceState) {

    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {


@Hardik Thaker 2013-07-23 05:58:21

@WilliamKinaan : anytime ;) :P

@Shan Xeeshi 2015-12-31 23:02:02

@HardikThaker I used your code it gives me exactly same keyhash that i got using terminal by this command keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 and I am still getting key hash does not match any stored key hash

@Avi C 2011-07-12 13:51:38

Here are the steps-

  1. Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)

  2. Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.

  3. detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step.

  4. detect your keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-

    $ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

    • it will ask for password, put android
    • that's all. u will get a key-hash

For more info visit here

@Miuranga 2011-09-07 04:34:48

good answer its work thank

@Walt Armour 2011-10-20 21:03:06

This answer almost worked for me on Win7 x64. However, the resulting encoded cert was incorrect. Bryan Bedard's answer below will produce the correct cert value. I'm guessing the piping on windows is somehow the culprit.

@Nicola Peluchetti 2011-12-03 19:07:34

Note for 64 bit users: this works with version openssl-0.9.8e X64 only do not use with openssl-0.9.8k X64

@Ravikiran 2012-02-08 08:42:40

I downloaded openssl-0.9.8e X64 for my system and extracted it.It contain nothing except one file with some data. Please help me to know more.

@Avi C 2012-02-08 10:16:27

Hi user915267, download it from this link-… It should work.

@Antrromet 2012-02-15 04:31:04

the command should be executed in the bin folder of java in windows systems.

@Hiren Dabhi 2012-03-23 07:30:54

it works. thanks

@nisha.113a5 2012-07-13 07:18:35

Good answer.. Thanks...........

@Ben Sewards 2013-07-16 01:46:21

@NicolaPeluchetti I'm running Win8 x64 bit and the "k" version worked for me and gave me a key-hash when I started the command off with ".\keytool ..." instead of "keytool ..."

@Morten Holmgaard 2013-10-15 17:53:19

Take a look at Shahar2k5 answer - it is so much easier!!

@bynu022 2014-10-17 12:31:00

works great.thankssss

@Hanish Sharma 2014-12-12 05:56:27

I got the key but its showing invalid switch - "$" please help where I'm wrong

@BIBIN K ONANKUNJU 2016-07-13 13:06:06

good answer its work thank

@Harsha 2016-11-08 13:00:45

am generating key hash for release app downlao dfrom store and login with facebook in my device no face book app so open dialog with facebook login page and working fine.if i installed facebook app and do the same process for login with facebook facebook login page coming in that entered my details and click login show that invalid keyhash error

@Utsav Gupta 2017-01-15 06:26:15

Can sombody explain what this command is doing ?

@Naeem Ibrahim 2017-01-20 12:14:25

Generate HashKey for debug and release mode by using this.…

@ban-geoengineering 2018-02-24 17:27:09

@HanishSharma Try leaving out the $.

@ban-geoengineering 2018-02-24 17:27:58

The default password for debug.keystore is android.

@Yohan Malshika 2019-01-18 07:29:12

Good answer and this help me lot.

@Bryan Bedard 2011-09-27 03:47:25

The instructions currently in Facebook's Android Tutorial do not work well under Windows. Their example shows how to pipe the keytool output to openssl but if you try this under Windows the output is not valid for some reason. I found that I had to use intermediary files to get it to work properly. Here are the steps that worked for me:

Start by downloading openssl for Windows from Google.

C:\Users\Me>keytool -exportcert -alias my_key -keystore my.keystore -storepass PASSWORD > mycert.bin

C:\Users\Me>openssl sha1 -binary mycert.bin > sha1.bin

C:\Users\Me>openssl base64 -in sha1.bin -out base64.txt

After running these commands the valid hash is stored in the file base64.txt. Copy and paste this to your app settings on Facebook.

@Oliver Dixon 2012-08-08 17:17:29

Works perfect, everything else was failing.

@Bobby 2012-11-21 19:46:09

What a PITA - but Bryan is right! The command will output a hash almost no matter what, whether your path is wrong, password is wrong, or the pipes aren't working right - you'll STILL GET A HASH but it won't work. So (on Windows) I ditched Powershell and tried Cygwin - still not working. Only after copying the debug.keystore file to the working dir could I get it to run and work!!

@Bobby 2012-11-21 19:47:15

So, in summary, on Windows, either use Bryan's technique of breaking it apart, OR use cygwin with your keystore file in the working dir : keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64 If it doesn't prompt you for a password then it didn't find the keystore file properly.

@OWADVL 2012-12-07 10:58:04

Thank you thank you thank you. !!!!!!!!! 1 hour wasted on this crap....

@Ron 2012-12-18 08:47:53

Worked perfectly for me. Great answer.

@Vaiden 2013-01-06 16:37:35

If you wanna avoid getting hashes for wrong password cases, just check your mycert.bin prior to continuing with the openSSL. Otherwise you'd be hashing the wrong password error text :)

@Vaiden 2013-01-06 16:38:23

Also, here are the alias and password for the Android debug keystore (auto-generated by the ADT) :…

@LeSam 2014-02-07 04:10:30

Where should I put the Openssl folder, once downloaded ? doesn't work for me

@Bryan Bedard 2014-02-16 05:28:53

It's been a long time since I did this but I'm pretty sure you can save openssl in whatever folder you want and you would just need to add an entry to your Path environment variable to point to that folder for the above command prompt commands to work.

@Gruff McGruff 2015-11-03 19:36:36

You can also put the above commands into a batch script and string them together with "&&"

@Daksh Agrawal 2017-08-01 14:01:33

It is saying Access is denied.

@hossaindoula 2011-06-26 08:37:28

You need to create a keystore by the keytool for signed apps for android like the procedure described in Android Site and then you have to install cygwin and then you need to install openssl from google code then just execute the following command and you will get the hash key for android and then put that hash key into the facebook application you created. And then you can access the facebook application through the Android Application for posting wall ("publish_stream") could be an example.

$ keytool -exportcert -alias alias_name -keystore sample_keystore.keystore | openssl sha1 -binary | openssl base64

You need to execute the above command from cygwin.

@Abhinav Manchanda 2010-12-14 13:22:23

1) Create a key to sign your application, and remember the alias.

2) Install OpenSSL.

3) Put the bin folder of OpenSSL in your path.

4) Follow the steps mentioned under "Setup Single Sign-On" on the FB-Android-SDK page, and generate your Hash Key. Make sure you put the correct alias and keystore file name.

5) Create an application on Facebok, and under Mobile Devices tab, enter this Hash Key.

Related Questions

Sponsored Content

77 Answered Questions

89 Answered Questions

[SOLVED] Close/hide the Android Soft Keyboard

33 Answered Questions

[SOLVED] How to avoid reverse engineering of an APK file?

27 Answered Questions

42 Answered Questions

[SOLVED] Is there a unique Android device ID?

25 Answered Questions

[SOLVED] Is there a way to run Python on Android?

40 Answered Questions

[SOLVED] Can't start Eclipse - Java was started but returned exit code=13

12 Answered Questions

[SOLVED] Proper use cases for Android UserManager.isUserAGoat()?

21 Answered Questions

[SOLVED] Facebook Android Generate Key Hash

12 Answered Questions

[SOLVED] How does Facebook disable the browser's integrated Developer Tools?

Sponsored Content