Key hash for Android-Facebook app
Solution 1
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
Solution 2
[EDIT 2020]-> Now I totally recommend the answer here, way easier using android studio, faster and no need to wright 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 ;)
Solution 3
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. :)
Solution 4
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.
Solution 5
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.
Related videos on Youtube
ravi babu
Updated on May 12, 2022Comments
-
ravi babu almost 2 years
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?
-
Nilanchala Panigrahy about 11 yearsyou may check this link javatechig.com/2012/12/10/…
-
Chintan Khetiya over 10 yearscheck this For those who are still facing issue ,
-
Naeem Ibrahim over 7 yearsGenerate HashKey for debug and release mode by using this. stackoverflow.com/questions/7506392/…
-
Soon Santos over 5 yearsTo get the keys watch this video
-
Faizan Haidar Khan over 2 yearsHere is the complete solution stackoverflow.com/a/68718505/8663316
-
-
Walt Armour over 12 yearsThis 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 over 12 yearsNote for 64 bit users: this works with version openssl-0.9.8e X64 only do not use with openssl-0.9.8k X64
-
Ravikiran about 12 yearsI 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.
-
Avisek Chakraborty about 12 yearsHi user915267, download it from this link- code.google.com/p/openssl-for-windows/downloads/… It should work.
-
Antrromet about 12 yearsthe command should be executed in the bin folder of java in windows systems.
-
Oliver Dixon over 11 yearsWorks perfect, everything else was failing.
-
Palani Kumar over 11 yearsGreat Answer. Thank you very much.
-
IgorGanapolsky over 11 yearsIs this for debug key or for release key?
-
Bobby over 11 yearsWhat 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 over 11 yearsSo, 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.
-
Ron over 11 yearsWorked perfectly for me. Great answer.
-
Vaiden over 11 yearsIf 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 over 11 yearsAlso, here are the alias and password for the Android debug keystore (auto-generated by the ADT) : developer.android.com/tools/publishing/…
-
Pallavi over 11 years@IgorGanapolsky instead of path of
myKeyStore
, give the path of your release key. The above code is for debug key -
Bassem Wissa about 11 yearsGuys, 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 ;)
-
Ben Sewards almost 11 years@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 ..."
-
Hardik Thaker almost 11 years@WilliamKinaan : anytime ;) :P
-
AnhSirk Dasarp over 10 yearsOpensssl always creating issues. This method is the best one. Just create a blank app , and get the key printed, Use it. Thanks man!!
-
Javal Nanda over 10 yearsI am getting different values with different alias name, how to verify which one is correct?
-
Biraj Zalavadia over 10 yearsit it asking for password with both the alias name ?
-
Javal Nanda over 10 yearsya 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 stackoverflow.com/questions/15021790/…
-
Biraj Zalavadia over 10 yearsyes there is a problem with widows with openssl. You can achieve with code specified in that post.
-
Biraj Zalavadia over 10 yearsIf 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
-
Morten Holmgaard over 10 yearsDefault path to debug.keystore: C:\Users\username\.android\debug.keystore
-
Morten Holmgaard over 10 yearsTake a look at Shahar2k5 answer - it is so much easier!!
-
Shahar over 10 years@MortenHolmgaard , I will try to add it in the near future, Tx for your comment.
-
Adam Varhegyi over 10 yearsBest. Method. Ever. Where is the donate button ?
-
Shahar over 10 years@AdamVarhegyi - Thanks, will add one in next version :)
-
Anearion over 10 yearsHi, 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 over 10 years@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 over 10 years@Shahar2k5 Don't know really, started again and worked like a charm. Sorry
-
LeSam about 10 yearsWhere should I put the Openssl folder, once downloaded ? doesn't work for me
-
Bryan Bedard about 10 yearsIt'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.
-
Vinayak about 10 yearsWorks like a charm! Thanks for sharing :)
-
MajorGeek over 9 yearsIts detected as Virus.whats the reason?
-
Shahar over 9 years@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 over 9 yearsHere is the link. s000.tinyupload.com/?file_id=32581246108406311297 My antivirus pops up as soon as the download is complete. The extension is facebookh2ko.exe.exe
-
Jack over 9 years@ShaharBarsheshetWhen I try and download this tool It installs a download manager instead of the tool?
-
Shahar over 9 years@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. i.imgur.com/YkHPY7k.png
-
MajorGeek over 9 years@Shahar Barsheshet Thank you. you are right. Downloaded from Devhost domain and no issue faced.
-
Hanish Sharma over 9 yearsI got the key but its showing invalid switch - "$" please help where I'm wrong
-
Nicklas Møller Jepsen over 9 years@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 over 8 yearsnow am using android studio.. above tool will able to use ?
-
Shahar over 8 years@harikrishnan sure! you just need the keystore file
-
Chris Cirefice over 8 yearsThis 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 -
Loolooii over 8 yearsThis code does not generate a valid hash key for me. @Jamshid's answer works for me on Mac OSX.
-
Omar Faroque Anik over 8 yearsIt creates wrong release key hash for me unfortunately
-
Shahar over 8 years@MdOmarFaroqueAnik i don't think that's possible, are you sure you are using the right file and the correct password and alias?
-
Gruff McGruff over 8 yearsYou can also put the above commands into a batch script and string them together with "&&"
-
wesley franks over 8 years@ Shahar hey I tried this and for some god awful reason my key was empty?
-
nightfixed over 8 yearsI 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 over 8 yearsit should, and it is. are you sure you are using the same keystore file for both?
-
Zeeshan over 8 years@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 -
benleung about 8 yearsgreat 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 :)
-
Harsha over 7 yearsam 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 over 7 yearsfor 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 over 7 yearsSimple way to resolve. You will display HashKey on screen. Just type that key on App settings facebook developer console.
-
sud007 over 7 yearsNO it asks for password. typing
android
gives a 24 digit hash and typinga
gives 28 digit hash. No idea why! -
Sébastien over 7 yearsIs this supposed to work to get a Release hash? (when running inside an APK signed with release keystore, of course).
-
Bassem Wissa over 7 yearsYes 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 :)
-
Akash Bisariya over 7 yearswhat is the password here?
-
Hiren Patel over 7 years@AkashBisariya, password of keystore, that you have given while creating the keystore.
-
Naeem Ibrahim over 7 yearsGenerate HashKey for debug and release mode by using this. stackoverflow.com/questions/7506392/…
-
Naeem Ibrahim over 7 yearsGenerate HashKey for debug and release mode by using this. stackoverflow.com/questions/7506392/…
-
Naeem Ibrahim over 7 yearsGenerate HashKey for debug and release mode by using this. stackoverflow.com/questions/7506392/…
-
CodeMonkey about 7 yearsEnjoy that beer friend.
-
KawaiKx about 7 yearsbad links! they don't have keytool at all
-
vlatkozelka about 7 yearsWe 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 about 7 years@vlatkozelka, check the source my friend bitbucket.org/PeleBit/keyhash_facebook_windows/src
-
Daksh Agrawal almost 7 yearsIt is saying
Access is denied.
-
Erich García over 6 yearsYes, great tool! @Shahar
-
ban-geoengineering about 6 years@HanishSharma Try leaving out the
$
. -
ban-geoengineering about 6 yearsThe default password for debug.keystore is
android
. -
Tabish about 6 yearsusing keytool is such a mess this is really simple
-
Anand Phadke over 5 yearsWhere I can find the key after successfully generated?
-
Yohan Malshika over 5 yearsGood answer and this help me lot.
-
Luca C. over 4 yearsthis is the simplest and most effective way, just take it from the logs without even openssl!
-
Khang Dinh Hoang over 4 yearsthis 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! -
Shashank Setty about 4 yearsTHANK YOU SO MUCH I CAN'T BEGIN TO EXPRESS HOW GREATFUL I AM
-
Green Y. about 4 yearsThanks. I tried to get key hash by using OpenSSL. It took me for 1 min and it was easy.
-
Harrison about 4 yearsThanks a lot! This was the solution as Google is signing my app now (I just use the upload certificate/keystore)
-
icyNerd about 3 yearsI got the development key hash but how do i get the release key hash?
-
icyNerd about 3 yearsYou 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 -
Biggg Jimmm about 3 yearsOnce 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.
-
Eli Nathan about 2 yearsThe link posted to fbKeyHash looks very sus...