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 readme.md (text file) in there, in which it is mentioned to generate the key hash for Android. How do I generate it?
-
2you may check this link http://javatechig.com/2012/12/10/how-to-get-key-hashes-for-android-facebook-app/ – Nilanchala Feb 04 '13 at 20:07
-
2check [this](http://chintankhetiya.wordpress.com/2013/12/26/how-to-create-facebook-hash-key-in-android/) For those who are still facing issue , – Chintan Khetiya Dec 26 '13 at 07:08
-
Generate HashKey for debug and release mode by using this. http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash/41763383#41763383 – Naeem Ibrahim Jan 20 '17 at 12:14
-
To get the keys watch [this](https://www.youtube.com/watch?v=7VJ1rRxiAEY) video – Soon Santos Aug 15 '18 at 11:17
-
Here is the complete solution https://stackoverflow.com/a/68718505/8663316 – Faizan Haidar Khan Aug 09 '21 at 22:10
35 Answers
Here are the steps-
Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)
Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.
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.
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\Administrator.android\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

- 8,229
- 10
- 48
- 76
-
5This 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. – Walt Armour Oct 20 '11 at 21:03
-
12Note for 64 bit users: this works with version openssl-0.9.8e X64 only do not use with openssl-0.9.8k X64 – Nicola Peluchetti Dec 03 '11 at 19:07
-
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. – Ravikiran Feb 08 '12 at 08:42
-
Hi user915267, download it from this link- http://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8e_X64.zip&can=2&q= It should work. – Avisek Chakraborty Feb 08 '12 at 10:16
-
2the command should be executed in the bin folder of java in windows systems. – Antrromet Feb 15 '12 at 04:31
-
@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 ..." – Ben Sewards Jul 16 '13 at 01:46
-
-
I got the key but its showing invalid switch - "$" please help where I'm wrong – Hanish Sharma Dec 12 '14 at 05:56
-
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 – Harsha Nov 08 '16 at 13:00
-
Generate HashKey for debug and release mode by using this. http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash/41763383#41763383 – Naeem Ibrahim Jan 20 '17 at 12:14
-
1
-
-
-
-
I got the development key hash but how do i get the release key hash? – eqrakhattak Mar 26 '21 at 20:38
[EDIT 2020]-> Now I totally recommend the answer here, way easier using android studio, faster and no need to write any code - the one below was back in the eclipse days :) -.
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("com.you.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
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 ;)

- 18,734
- 5
- 61
- 83

- 2,947
- 1
- 20
- 20
-
31Guys, 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 ;) – Bassem Wissa Apr 22 '13 at 13:48
-
4Opensssl always creating issues. This method is the best one. Just create a blank app , and get the key printed, Use it. Thanks man!! – AnhSirk Dasarp Sep 05 '13 at 05:35
-
1This 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 – Chris Cirefice Aug 15 '15 at 17:32
-
Is this supposed to work to get a Release hash? (when running inside an APK signed with release keystore, of course). – Sébastien Dec 09 '16 at 15:57
-
1Yes 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 :) – Bassem Wissa Dec 10 '16 at 20:36
-
Generate HashKey for debug and release mode by using this. http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash/41763383#41763383 – Naeem Ibrahim Jan 20 '17 at 12:14
-
1
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. :)

- 3,692
- 4
- 25
- 47
-
Default path to debug.keystore: C:\Users\username\.android\debug.keystore – Morten Holmgaard Oct 15 '13 at 17:29
-
@MortenHolmgaard , I will try to add it in the near future, Tx for your comment. – Shahar Oct 26 '13 at 23:58
-
1
-
-
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. – Anearion Jan 07 '14 at 10:13
-
@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. – Shahar Jan 07 '14 at 10:52
-
1@Shahar2k5 Don't know really, started again and worked like a charm. Sorry – Anearion Jan 07 '14 at 16: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... – Shahar Dec 02 '14 at 20:12
-
Here is the link. http://s000.tinyupload.com/?file_id=32581246108406311297 My antivirus pops up as soon as the download is complete. The extension is facebookh2ko.exe.exe – MajorGeek Dec 03 '14 at 10:23
-
@ShaharBarsheshetWhen I try and download this tool It installs a download manager instead of the tool? – Jack Dec 09 '14 at 18:42
-
@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 "d-h.st" check the image for more details. please update if that solved your issues. http://i.imgur.com/YkHPY7k.png – Shahar Dec 10 '14 at 10:48
-
1@Shahar Barsheshet Thank you. you are right. Downloaded from Devhost domain and no issue faced. – MajorGeek Dec 10 '14 at 15:40
-
@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. – Nicklas Møller Jepsen Dec 31 '14 at 12:22
-
-
-
-
@MdOmarFaroqueAnik i don't think that's possible, are you sure you are using the right file and the correct password and alias? – Shahar Oct 03 '15 at 16:42
-
@ Shahar hey I tried this and for some god awful reason my key was empty? – wesley franks Dec 13 '15 at 02:23
-
1I 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? – nightfixed Dec 20 '15 at 19:01
-
it should, and it is. are you sure you are using the same keystore file for both? – Shahar Dec 21 '15 at 04:24
-
Generate HashKey for debug and release mode by using this. http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash/41763383#41763383 – Naeem Ibrahim Jan 20 '17 at 12:14
-
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... – vlatkozelka May 04 '17 at 06:33
-
@vlatkozelka, check the source my friend https://bitbucket.org/PeleBit/keyhash_facebook_windows/src – Shahar May 04 '17 at 09:15
-
@nightfixed It seems the tool creates a different hash key than `keytool` and `http://tomeko.net/online_tools/hex_to_base64.php` website for the same keystroke file and identical settings. – Maverick Jul 26 '23 at 13:10
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.

- 2,619
- 1
- 23
- 22
-
-
2What 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 Nov 21 '12 at 19:46
-
2So, 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. – Bobby Nov 21 '12 at 19:47
-
-
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 Jan 06 '13 at 16:37
-
Also, here are the alias and password for the Android debug keystore (auto-generated by the ADT) : http://developer.android.com/tools/publishing/app-signing.html#debugmode – Vaiden Jan 06 '13 at 16:38
-
Where should I put the Openssl folder, once downloaded ? doesn't work for me – LeSam Feb 07 '14 at 04:10
-
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. – Bryan Bedard Feb 16 '14 at 05:28
-
You can also put the above commands into a batch script and string them together with "&&" – Gruff McGruff Nov 03 '15 at 19:36
-
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.
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.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.
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
folderReplace 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, "|".
If prompted for a password, enter
android
.
And you will get your hash key. For further steps, refer again to the Facebook page.

- 30,738
- 21
- 105
- 131

- 6,532
- 3
- 48
- 70
You can get key hash from SHA-1 key.
Its very simple you need to get your SHA-1(Signed APK) key from Play Store check below image.
Now Copy that SHA-1 key and past it in this website http://tomeko.net also check below image to get your Key Hash.

- 2,139
- 20
- 27
-
1Thanks. I tried to get key hash by using OpenSSL. It took me for 1 min and it was easy. – Green Y. Apr 03 '20 at 16:15
-
1Thanks a lot! This was the solution as Google is signing my app now (I just use the upload certificate/keystore) – Harrison Apr 14 '20 at 16:37
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(
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) {
}
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.

- 31,250
- 24
- 137
- 216
-
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 :) – benleung Feb 13 '16 at 17:56
To get the Android key hash code, follow these steps:
- Download OpenSSL for Windows here
- Now unzip to the C drive
- Open a CMD prompt
- Type
cd C:\Program Files\Java\jdk1.6.0_26\bin
- 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
- Done

- 30,738
- 21
- 105
- 131

- 4,195
- 1
- 32
- 27
-
1
-
@IgorGanapolsky instead of path of `myKeyStore`, give the path of your release key. The above code is for debug key – PrincessLeiha Jan 10 '13 at 14:01
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 http://www.facebook.com/developers
Copy "abcdefgHIJKLMN+OPqrstuvwzyz" and paste it into the Facebook Android Key Hash area.

- 30,738
- 21
- 105
- 131

- 171
- 1
- 2
-
this is the simplest and most effective way, just take it from the logs without even openssl! – Luca C. Aug 12 '19 at 09:23
-
this is the only worked solution for me!. I don't see the log like you, but I see this `KeyHash: XWwXXXXX/5xxxxxxxxxxx=` in the log and helped me out! – Khang Dinh Hoang Aug 13 '19 at 07:04
I have done by this way for Linux OS & Windows OS:
Linux:
- 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.
Windows:
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.
Note:
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.
Done

- 52,124
- 21
- 173
- 151
-
-
@AkashBisariya, password of keystore, that you have given while creating the keystore. – Hiren Patel Dec 21 '16 at 10:13
-
-
You can find the **release hash key** by `keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64` in *Linux*, *Windows* and *MacOS* – eqrakhattak Mar 26 '21 at 20: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
C:\Users\username\.android\debug.keystore
- now get your command prompt and paste this code
keytool -exportcert -alias androiddebugkey -keystore C:\Users\username.android\debug.keystore | "C:\openSSL\bin\openssl" sha1 -binary | "C:\openSSL\bin\openssl" base64
- hit enter and you will get the 28 digit keycode

- 3,064
- 28
- 22
-
NO it asks for password. typing `android` gives a 24 digit hash and typing `a` gives 28 digit hash. No idea why! – sud007 Dec 02 '16 at 18:15
-
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.

- 4,637
- 39
- 52
- 71

- 761
- 6
- 24
Simply Open you Main Activity File and create below mention function:
try { PackageInfo info = getPackageManager().getPackageInfo( "your.application.package.name", 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 (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { }
1.1 Run you Application, this will generate a Hash key for your application.
Now, Open log cat and search with "KeyHash" and copy the hash key.
One you generate the Hash key you can remove this function.

- 1,050
- 10
- 20
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.

- 980
- 10
- 21
Official Documentation on facebook developer site:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
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) {
} catch (NoSuchAlgorithmException e) {
}

- 3,050
- 1
- 27
- 37
-
-
@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 – Zeeshan Dec 31 '15 at 23:02
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("com.app.helpcove", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
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) {
}
}

- 1,852
- 1
- 23
- 19
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.

- 6,546
- 3
- 39
- 46
There are two methods available complex one and the easy one
Methods One :(little Complex)
first of all you have to download ssl 64bit
or 32bit
accordingly, remember to download the file with name containing e
after version code openssl-0.9.8e_X64.zip OR openssl-0.9.8e_WIN32.zip not with the k
after the version code,
and place in AndroidStudio/jre/bin directory, if you dont know where to place, you can find this directory by right clicking on the android studio shortcut as:
now you have managed two required things in one place, but still you have to find the path for your debug.keystore
, that is always can be found in the "C:\Users\yourusernamehere\.android\debug.keystore"
,
NOTE If your app is published already, or about to publish then use your publishing signing keystore, if and only if your are testing in development mode than you can use debug,keysotre
As everything is setup, let arrange the command you wanted to execute for the hash key generation in base64 format
, and you command will look like this
keytool.exe -exportcert -alias androiddebugkey -keystore "C:\Users\ayyaz talat\.android\debug.keystore" | "D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" sha1 -binary |"D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" base64
it will promt you to enter a password for the debug.keystore, which is android by default. if you are using your own key than the password will be also yours. the output will look like this if everything goes well as expected, hope it may help
Second Method (Respectively easy one)
if you dont want to go throught all the above procedure, then just use the following method to log the haskey:
private void printKeyHash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("KeyHash:", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", e.toString());
}
}
output:

- 896
- 12
- 18
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 ...
Steps:
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

- 1,244
- 10
- 25

- 665
- 6
- 17
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.

- 28,348
- 10
- 61
- 77
-
I am getting different values with different alias name, how to verify which one is correct? – Javal Nanda Sep 26 '13 at 12:21
-
-
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 http://stackoverflow.com/questions/15021790/remote-app-id-does-not-match-stored-id-exception – Javal Nanda Sep 26 '13 at 12:30
-
yes there is a problem with widows with openssl. You can achieve with code specified in that post. – Biraj Zalavadia Sep 26 '13 at 12:36
-
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 – Biraj Zalavadia Sep 26 '13 at 12:41
-
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 – Harsha Nov 09 '16 at 09:46
-
Simple way to resolve. You will display HashKey on screen. Just type that key on App settings facebook developer console. – Biraj Zalavadia Nov 09 '16 at 09:55
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=)

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

- 1,053
- 3
- 11
- 28
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.
image: fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2178-6/851568_627654437290708_1803108402_n.png
Refer from : https://developers.facebook.com/docs/android/getting-started#release-key-hash and http://note.taable.com

- 237
- 3
- 2
Use this for print key hash in kotlin
try {
val info = context.getPackageManager().getPackageInfo(context.packageName,
PackageManager.GET_SIGNATURES);
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
Log.d("Key hash ", android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT))
}
}catch (e:Exception){
}

- 3,469
- 5
- 24
- 38
Solved mine too in Android Studio but with slight different approach.
To get the SHA-1 value in Android Studio.
- Click Gradle
- Click Signing Report
- Copy SHA-1
SHA-1 value look like this CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84
and open http://tomeko.net/online_tools/hex_to_base64.php to convert your SHA1 value to base64. This is what Facebook requires get the generated hash " ********************= " and copy the key hash to the facebook app console.
Part of this answer taken from here Github Link

- 105
- 2
- 5
In Android Studio just click on right sidebar panel "Gradle" to show gardel panel then: -YOURAPPNAME --Task ---Android ----(double click) signingReport (to start Gradle Daemon)
then you will see result:
Config: debug
Store: C:\Users\username\.android\debug.keystore
Alias: AndroidDebugKey
MD5: C8:46:01:EA:36:02:D1:21:1B:23:19:91:D4:32:CB:AC
SHA1: 38:AB:4C:01:01:D7:62:E0:61:D1:9F:52:04:0C:E5:07:4E:E4:9B:39
SHA-256: 1B:8C:DC:35:48:10:01:2C:1F:BD:01:64:F1:01:06:01:60:01:A6:8B:10:15:2E:BF:7B:C4:FD:38:4C:C1:74:01
Valid until: Saturday, February 12, 2050
copy SHA1:
38:AB:4C:01:01:D7:62:E0:68:D1:9F:52:04:0C:E5:07:4E:E4:9B:39
go to this PAGE
Paste SHA1 and generate your Facebook key hash code.

- 177
- 2
- 6
-
2Once your app is in play store, you need to generate 2 keyhashes: One for the SHA1 you used to generate the APK OR AAB The second to for the SHA1 generated by google. – Biggg Jimmm Apr 11 '21 at 17:35
-
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.
Cool.

- 30,738
- 21
- 105
- 131

- 665
- 6
- 17
The best approach is to use the following code:
private void getHashKey(String pkgName)
{
try
{
PackageInfo info = getPackageManager().getPackageInfo(pkgName, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures)
{
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = Base64.encodeBytes(md.digest());
_hashKey_et.setText(hashKey);
Log.i("KeyTool", pkgName + " -> hashKey = " + hashKey);
}
}
catch (NameNotFoundException e)
{
e.printStackTrace();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
}
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 :)

- 326
- 3
- 7
Here is Xamarin version
private void printKeyHash()
{
try
{
PackageInfo info = PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.Signatures);
foreach (var signature in info.Signatures)
{
MessageDigest md = MessageDigest.GetInstance("SHA1");
md.Update(signature.ToByteArray());
var hash = Base64.EncodeToString(md.Digest(), Base64Flags.Default);
Log.Debug("KeyHash:", hash);
}
}
catch (PackageManager.NameNotFoundException e)
{
}
catch (NoSuchAlgorithmException e)
{
}
}

- 2,137
- 23
- 24
Kotlin code to get Hash key
private fun logHashKey() {
try {
val info = getPackageManager().getPackageInfo("your.package.name", PackageManager.GET_SIGNING_CERTIFICATES);
for (signature in info.signingInfo.signingCertificateHistory) {
val md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
val something = Base64.getEncoder().encodeToString(md.digest());
Log.e("hash key", something);
}
} catch (e1: PackageManager.NameNotFoundException) {
Log.e("name not found", e1.toString());
} catch (e: NoSuchAlgorithmException) {
Log.e("no such an algorithm", e.toString());
} catch (e: Exception) {
Log.e("exception", e.toString());
}
}
Please don't forgot to generate keys in Debug and Release environment as they change as per build setting.

- 96
- 6
try this :
- two way to get Hash Key Value
1) get hash key from using command line (Official Doc : https://developers.facebook.com/docs/android/getting-started)
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl
base64
OR
2) get hash key using code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Hask Kay generation
GetKeyHase();
}
private void GetKeyHase() {
try {
PackageInfo info = getPackageManager().getPackageInfo("ADD YOUR PACKAGE NAME", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = (MessageDigest.getInstance("SHA"));
md.update(signature.toByteArray());
String hashkey_value = new String(Base64.encode(md.digest(), 0));
Log.e("hash key", hashkey_value);
//check you logcat hash key value
}
}catch (Exception e) {
Log.e("exception", e.toString());
}
}

- 465
- 6
- 12
I just made a tool for that exact purpose i.e., https://keyhash.vaibhavpandey.com/. It is simpler than anything else as it requires you browse the keystore on your computer and enter the passphrase to generate both SHA-1 Hex and Base64 versions for Google & Facebook respectively.
Don't worry about the keystore or passphrase as the job is done completely in-browser, you can inspect the network tab and the tool is open-source too at https://github.com/vaibhavpandeyvpz/keyhash.
This required no coding input. Go to Android Studio->
Click on Right side panel "Gradle"=>
*Your App Name =>
*Your App Name(root)=>
*Tasks=>
*android =>
*Double click on **signinReport**=>
Will get
example :
SHA1: [![6A:DE:ED:5A:9F:0B:19:47:38:DC:DE:3B:7B:A2:D7:4C:6C:0A:24:70][1]][1]
Go to
http://fbkeyhash.com/index.php
Paste your SHA-1

- 881
- 10
- 25
You can print the Hash Key from Java/Kotlin Activity. Some part of the code is deprecated but here is the complete solution with old and new code.
private fun printHashKey(context: Context) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val packageInfo: PackageInfo = context.packageManager.getPackageInfo(
context.packageName,
PackageManager.GET_SIGNING_CERTIFICATES
)
for (signature in packageInfo.signingInfo.apkContentsSigners) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
}
} else {
val packageInfo: PackageInfo = context.packageManager.getPackageInfo(
context.packageName,
PackageManager.GET_SIGNATURES
)
for (signature in packageInfo.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
}
}
} catch (e: PackageManager.NameNotFoundException) {
Log.d(TAG, "printHashKey: PackageManager.NameNotFoundException -> $e")
} catch (e: NoSuchAlgorithmException) {
Log.d(TAG, "printHashKey: NoSuchAlgorithmException -> $e")
}
}

- 1,099
- 1
- 15
- 20
This is the method that worked for me along with few observations that I made :
Each SHA1 key will have a corresponding key hash which is 28 characters long and ends with a '='
I have tried the online tools to get the hash key out of my SHA1 but that key hash never worked for me.
If you are on windows install the open-ssl from here :Open ssl
I had used this keytool command on all the keystore files that I had i.e., staging, debug and release.
keytool -exportcert -alias my_alias_name -keystore "C:\Users\...my_filename.jks" | "C:\Openssl\bin\openssl.exe" sha1 -binary | "C:\Openssl\bin\openssl.exe" base64
Note: The above method will always give you a key hash even if you filled any of the parameters incorrectly . The trick to know you if are getting the right hash key is- after running this command if you are prompted for password , it means that the subsequent key is the right one.
Don't use my_filename.keystore but instead use my_filename.jks .

- 225
- 2
- 9