Facebook Android Generate Key Hash
Solution 1
Delete your debug certificate under ~/.android/debug.keystore (on Linux and Mac OS X); the directory is something like %USERHOME%/.android on Windows.
The Eclipse plugin should then generate a new certificate when you next try to build a debug package.
Let me know if that works.
Solution 2
In order to generate key hash you need to follow some easy steps.
1) Download Openssl from: here.
2) Make a openssl folder in C drive
3) Extract Zip files into this openssl folder created in C Drive.
4) Copy the File debug.keystore from .android folder in my case (C:\Users\SYSTEM.android) and paste into JDK bin Folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin)
5) Open command prompt and give the path of JDK Bin folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin).
6) Copy the following code and hit enter
keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt
7) Now you need to enter password, Password = android.
8) If you see in openssl Bin folder, you will get a file with the name of debug.txt
9) Now either you can restart command prompt or work with existing command prompt
10) get back to C drive and give the path of openssl Bin folder
11) copy the following code and paste
openssl sha1 -binary debug.txt > debug_sha.txt
12) you will get debug_sha.txt in openssl bin folder
13) Again copy following code and paste
openssl base64 -in debug_sha.txt > debug_base64.txt
14) you will get debug_base64.txt in openssl bin folder
15) open debug_base64.txt file Here is your Key hash.
Solution 3
UPDATED ANSWER (Generating through code) Simpler method :
In my experience, openssl always being troublesome, I tried the second method suggested by facebook. And it's wonderful. This is the best method to get the hash key.
Second option is to print out the key hash sent to Facebook and use that value. Make the following changes to the onCreate() method in your main activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.loginhowto",
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) {
}
...other operations
}//end of onCreate
Replace com.facebook.samples.loginhowto with your own package name ( package name in Manifest.xml).
Official link - https://developers.facebook.com/docs/android/login-with-facebook/ ( See the bottom of the page)
OLD ANSWER (Generating Keyhash using openssl )
- to generate signature you need openssl installed on your pc. If you don’t have one download openssl from here
- In C: , Create
openssl
folder - extract the contents of downloaded openssl zip file into
openssl
folder inC:
drive - open Command prompt
- move to
bin
ofopenssl
i.eC:\openssl\bin
in command prompt -
run the following command to generate your keyhash. While generating hashkey it should ask you password.
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Anhsirk.android\debug.keystore" | openssl sha1 -binary | openssl base64
NOTE: in the above code note that , you need to give your path to user ( i.e in my case it is C:\Users\Anhsirk , you just need to change this for your user account.
Give password as android
. If it don’t ask for password your keystore path is incorrect.
If everything works fine, it should give you the hashkey below.
Solution 4
Simplest way to generate hash key.
Requirement: SHA1 Key
You can get SHA1 Key from your keystore file by two ways
1) Locate your keystore file, open command prompt on that location then use below mentioned command
keytool -list -v -keystore {keystore_name} -alias {alias_name}
and then enter your password then it will return md5, sha1 and sha256 key.
OR
2) By running signingReport
Refer below image.
after you run the file your output will be generated containing required sha1 key.
After you get the required SHA1 Key
Then goto
http://tomeko.net/online_tools/hex_to_base64.php
and paste your sha1 key
and finally you will get Required HashKey which you can use it to apply on facebook.
Solution 5
The right key can be obtained from the app itself by adding the following code to toast the proper key hash (in case of Facebook SDK 3.0 onwards, this works)
try {
PackageInfo info = getPackageManager().getPackageInfo("com.package.mypackage", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.e("MY KEY HASH:", sign);
Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Replace com.package.mypackage with your package name
Comments
-
Scott over 3 years
Trying to create an android app with Facebook integration, I've gotten to the part in the docs where you have to generate a key hash file, it specifies to run the following code
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
When I run this in my terminal I get an error for Keystore tampered with or password was incorrect,
I just want to generate my Key Hash
Can anyone point me in the right direction?
-
BBdev almost 12 yearsnice answer +1 for you i have followed this and get the desired result :)
-
KunalK over 11 yearsHi, i've tried using my application keystore to generate the keyhash, but whenever i try to share anything from my application it gives me error that Application is misconfigured for Facebook login. but when i try keyhash generated through debug.keystore it works. can u please help me on this.?
-
DuyguK over 11 yearsI am getting this: keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect.How can i find my correct password?
-
DuyguK over 11 yearsI am getting this: keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect.How can i find my correct password?
-
AnhSirk Dasarp over 11 years@DuyguK - probably means that your key-store already exists. Try deleting that and redo. Or a wrong path you may have specified
-
rennoDeniro about 11 yearsThis worked for me after 2 days of confusion to what was going on. Brilliant work!
-
Emran Hamza about 11 years@ DuyguK: put password as android then press enter, Then you will not get this error message keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect.How can i find my correct password?
-
Emran Hamza about 11 years@Vizzz: Nice way of explain for generating key hash. Thanks for this post, hope this post will save a lot of time of some one.
-
Naveen Kumar over 10 yearsIn my case when i run this command in cmd openssl sha1 -binary debug.txt > debug_sha.txt it gives the error Access is denied.
-
TacB0sS over 10 yearsWhat I don't understand is, if it took me a couple of hours to learn it all and sketch this up, why none of the big companies have done this already to provide us with an easy way to get the info they ask from us???
-
Yenthe over 10 yearsGod this took me hours. Thank you so much!
-
Alexander Farber about 10 yearsThis is great info for Adobe AIR apps developers (Flash or Apache Flex). And the "Class Name" for Facebook SSO should be
AppEntry
-
marson almost 10 yearsI want to ask, if the new method (get keyhashes by code) slows somehow the onCreate process. Because from what i know, when the signed APK is created, the keyhashes are different. Thanks for the code anyways!:)
-
CthulhuJon over 9 yearsdidn't work. deleted the debug.keystore file, made debug build, file never came back. noting else in that folder updated.
-
Diljeet over 9 yearsI tried every code but never got the desired output. i tried code from facebook it also is the same just all three commands in one command, but running three commands seperately gave the right code and worked, hour of search or maybe days of search. Thanks. Before this only the code on android app was giving right result, command prompt gave invalid keys, now all is well. Thanks again
-
akshay7692 about 9 yearsjust a note : you need to put '=' after the key copied from log
-
Admin about 9 yearswill the simpler method work without emulator but on the real android device?
-
iOSAndroidWindowsMobileAppsDev about 8 years@VijayArora Your install instructions are clear but the second openssl results in an 'access denied' error it was asier to use this one line: keytool -exportcert -alias androiddebugkey -keystore "%USERPROFILE%\.android\debug.keystore" | C:\openssl\bin\openssl.exe sha1 -binary | C:\openssl\bin\openssl.exe base64
-
Harsha over 7 yearsbut it showing asking password am giving signed keystore password also and then showing chines laungauge
-
Enoobong over 7 yearsI really don't know how this is the accepted answer?
-
Farrukh Faizy over 7 yearsBest ans on Stack
-
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/…
-
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/…
-
KawaiKx about 7 yearsensure that the path is correctly set for openssl\bin and java...\bin
-
Oscar Ortiz almost 7 yearsThank you so much. Can't believe Facebook doesn't explain this all
-
luiswill over 6 yearsThat's for the debug environnement so it means just to test not when it's published. If you want release key hash :
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64
more info on Facebook Docs -
luiswill over 6 yearsThat's for the debug environnement so it means just to test not when it's published. If you want release key hash :
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64
more info on Facebook Docs -
me-- over 5 yearsFor me, this generates a 64 character string, but the Facebook UI insists that it should be 28 characters.
-
Hiren Dabhi over 5 years
GET_SIGNATURES
deprecated now. -
Calvin about 5 years@AnhSirkDasarp is it possible to decrypt the key hash on server and verify the authenticity of the request?
-
hakuna1811 about 5 yearsFor anyone that tried but still does not work, use storepass as extra params, like this
keytool -exportcert -alias MY_APP_DEBUG -storepass 678910 -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
-
hakuna1811 about 5 yearsThis answer is much simpler than the others since it only cares about the final output. Always correct. In other cases, if the signing process misconfigured, we won't know how to fix.
-
Dheeraj Jaiswal about 5 yearsAwesome Work like charm Thank buddy
-
ACAkgul almost 4 yearsI can't believe this method make me realized I ve been writing "upper case i" letter as "lower case L" in the hash key which facebook show me. Thank you.
-
S_i_l_e_n_t C_o_d_e_r almost 3 yearsThis answer is easy way to generate Hash Key. Thank You