Facebook Android Generate Key Hash
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?
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.
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.
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.
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
I. Create key hash debug for facebook
Add code to print out the key hash for facebook
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.google.shoppingvn", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("KeyHash:",
Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
II. Create key hash release for facebook
Download openssl-0.9.8e_X64
Make a openssl folder in C drive
Extract Zip files into openssl folder
Start -> Run: cmd (press enter)
(press) cd C:\Program Files\Java\jdk1.6.0_45\bin. Note: C:\Program Files\Java\jdk1.6.0_45\bin: is path to jdk folder in your computer
(press) keytool -exportcert -alias gci -keystore D:\folder\keystorerelease | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl base64. Note: D:\folder\keystorerelease: is path to your keystorerelease
Enter keystore password: This is password when your register keystorerelease.
Then you will have a key hash: jDehABCDIQEDWAYz5Ow4sjsxLSw=
Login facebook. Access to Manage Apps. Paste key hash to your app on developers.facebook.com
SIMPLEST SOLUTION OUT THERE FOR THIS PROBLEM:
I have had this Problem for two months now. My key hashes have been pyling up to 9. Today i finally found the simple solution:
STEP 1:
Install the facebook sdk you downloaded from the facebook developer page on your phone. Don´t install the normal facebook app. Make sure you can log into facebook. Then log out.
STEP 2:
Export your app with your final release key as an apk, like you would when uploading it to the playstore.
STEP 3:
Put the Apk file on your phone via usb cable or usb stick.
STEP 4:
Install your app, using a file manager: Example
STEP 5:
Launch your app and try to log in with facebook. A dialog will open and tell you: "the key YOURHASHKEY has not been found in the facebook developer console"
STEP 6:
Write down the key.
STEP 7:
Put it into your facebook developer console and save. Now you are done. Anyone that downloads your app, published with earlier used keystore can log into facebook.
Enjoy
If you are releasing, use the keystore you used to export your app with and not the debug.keystore.
The password of the debug certificate is android and not Android
At last :)
Here my story :
Add this code to your main activity, after you set layout.
try { PackageInfo info = getPackageManager().getPackageInfo("PROJECTNAME", 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); //textInstructionsOrLink = (TextView)findViewById(R.id.textstring); //textInstructionsOrLink.setText(sign); Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show(); } } catch (NameNotFoundException e) { Log.d("nope","nope"); } catch (NoSuchAlgorithmException e) { }
Change PROJECTNAME to your package name!
- Sign your app (Android Tools->Export Signed Application)
- In your main activity where you paste code from 2 option, in your layout create TextView with id textstring
- uncomment two lines, that your sign code would be set to TextView 6 Wuolia, you have your HASH , install app on your phone!!! and check your hash Key!
- Now when it is visible , go to facebook app you created and add it to [Key Hashes]
- Note that your package name should be same as on facebook [Package Name] under [Key Hashes]
- Have a nice day :)
One line solution to generate for facebook
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
In order to generate release key hash you need to follow some easy steps.
1) Download Openssl
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.7.0_40\bin).
6) Copy the following code and hit enter
keytool -exportcert -alias abcd-keystore D:\Projects\MyAppFolder\keystore.txt | C:\openssl\bin\openssl sha1 - binary | C:\openssl\bin\openssl base64 ex - keytool -exportcert -alias (your sing apk alias name enter here like my sign apk alian name is abcd )-keystore "signed apk generated keystore apth enter here" | "openssl bin folder path enter here" sha1 - binary | "openssl bin folder path enter here" base64
7) Now you need to enter password, Password = (enter your sign keystore password here)
8) you got keystore which are used for release app key hash
Even though this thread is old, yet I would like to share my experience (recently started working with facebook), which seems to me straight:
- Download openssl from the link bellow: https://code.google.com/p/openssl-for-windows/downloads/list
- Unzip it to a local drive (e.g., C:\openssl)
To get the Development key for facebook integration, use the following command from the command line in windows:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
NOTE!: please replace the path for openssl.exe (in this example it is "C:\openssl\bin\openssl.exe") with your own installation path.
- It will prompt for password, e.g.,
Enter keystore password: android
Type android as password as shown above.
Thats it! You will be given a 28 character long key. Cheers!
Use the same procedure to get the Release key. Just replace the command with the following and use your release key alias.
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | "PATH FOR openssl.exe" sha1 -binary | openssl base64
Generate Debug hash key
public String hashkey(Context context) {
String keyhash = "";
try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.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));
keyhash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
return keyhash;
}
Generate Release hash key
keytool -exportcert -alias specialbridge -keystore /home/shilpi/newproject/specialBridge/SpecialBridgeAndroid/keystore/specialbridge.jks | openssl sha1 -binary | openssl base64
Great blog post on the subject
Extracting the Key Hash from .p12 key
- Open Terminal or Command line and navigate to where your .p12 key is.
- Type in: “keytool -v -list -keystore mycert.p12 -storetype pkcs12″ where mycert.p12 is the filename of your .p12 key.
- Enter keystore password (the one you used when exported .p12 key). 4 . Copy sha1 fingerprint signature bytes text.
- The bytes at sha1 fingerprint signature are needed to write the “sha1.bin” file. You can use a hexadecimal editor to paste the bytes you copied. Afterwards, save the file as “sha1.bin”.
- Open terminal again and type in: “openssl base64 -in sha1.bin -out base64.txt”.
- The resulting “base64.txt” will contain the Key Hash that is needed for Facebook.
Great and simple hexadecimal editor for mac: HexFiend
OpenSSL should be preinstalled on mac, and here is the link for Windows version.
Link
Try passing the password for the key and store as part of the command
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -keypass android -storepass android \
| openssl sha1 -binary \
| openssl base64
I was able to do perform the requested task with some of the solutions here, but thought to myself, boy that is stupid... why not to write a small Java code that does this and pack it into a Jar, so I did...
A link to download the Jar
Works on Windows 8... didn't try any other OS.
Hi everyone its my story how i get signed has key for facebook
first of all you just have copy this 2 methods in your first class
private void getAppKeyHash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), 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));
System.out.println("HASH " + something);
showSignedHashKey(something);
}
} catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
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());
}
}
public void showSignedHashKey(String hashKey) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Note Signed Hash Key");
adb.setMessage(hashKey);
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
adb.show();
}
**Call funcation getAppKeyHash() from your oncreate methode if you want signed hash then make signed build install signed build and run you will get hash key in dialog then just note it and update it on facebook dev account and comment that function and make another signed APK **
If your password=android is wrong then Put your pc password on that it works for me.
And for generate keyHash try this link Here
The only thing working for me is using the password android
. Why is that not mentioned in any guides out there?
use this in kotlin for print key hash in log
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){
}
精彩评论