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
For more info visit here
[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 ;)
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. :)
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.
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
folder
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, "|".
If prompted for a password, enter android
.
And you will get your hash key. For further steps, refer again to the Facebook page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With