Find the key hash for a signed app
- You should know where is your keystore file. For me is
C:\Users\Selvin\Desktop\selvin.kp
- You should know your alias in keystore. For me is
selvin
- You should know path to keytool.
C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe
- You should know path to openssl.
C:\OpenSSL-Win32\bin\openssl.exe
- You should know password to keystore. For me is ***** hehe
Then, you should call:
C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe" -exportcert -alias selvin -keystore c:\users\selvin\desktop\selvin.kp | C:\OpenSSL-Win32\bin\openssl sha1 -binary | C:\OpenSSL-Win32\bin\openssl base64
Replace my path and alias with proper ones.
Then you should see:
Enter keystore password:
Enter your password and you should get something like this: NfhDlIH7XWJzUZRjL+pZySrMX1Q=
EDITED: NfgDlIG7XWJzUZRUL+bZySrMX1Q=
<- is a bad hash. Or you got so lucky that your key made the same collision as
error:keytool error: java.lang.Exception: Alias does not exist
If hash not working:
First, call
C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe" -exportcert -alias selvin -keystore c:\users\selvin\desktop\selvin.kp
Type password and read the error
If you don't remember your alias keytool error: java.lang.Exception: Alias <selvinn> does not exist
I used selvinn to show error.
For a list of all your entries/aliases:
C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe -list -keystore c:\users\selvin\desktop\selvin.kp
second edit
Is there any way to get key hash from signed APK?
For windows users getting the key from openssl, may be tricky some times.. I always use this to find the right
signature.. Just paste this code in your onCreate() and run.
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Update:
Using Android studio(2.1.2):
- Open your project on studio and click on the gradle icon.
- Choose your app -> Tasks -> android -> SigningReport
This will run a gradle task that will print the debug and release certificate with md5 and sha1 keys
Google play app signing key hash
You can extract keyhash from the Sha1 certificate signature. Key hashes are usually extracted in the following way:
public static String getKeyHash(final Context context) {
PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_SIGNATURES);
if (packageInfo == null)
return null;
for (Signature signature : packageInfo.signatures) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
return Base64.encodeToString(md.digest(), Base64.NO_WRAP);
} catch (NoSuchAlgorithmException e) {
Log.w(TAG, "Unable to get MessageDigest. signature=" + signature, e);
}
}
return null;
}
You can see that SHA-1 version of signature is Base64 encoded.
Under App Signing menu in Google play developer console, you will see Sha-1 certificate signature that looks like this:
SHA1: 3B:DA:A0:5B:4F:35:71:02:4E:27:22:B9:AC:B2:77:2F:9D:A9:9B:D9
Basically, what you have to do is to change this into a byte array and Base64 encode that byte array. You can do something like:
byte[] sha1 = {
0x3B, (byte)0xDA, (byte)0xA0, 0x5B, 0x4F, 0x35, 0x71, 0x02, 0x4E, 0x27, 0x22, (byte)0xB9, (byte)0xAc, (byte)0xB2, 0x77, 0x2F, (byte)0x9D, (byte)0xA9, (byte)0x9B, (byte)0xD9
};
Log.e("keyhash", Base64.encodeToString(sha1, Base64.NO_WRAP));
You can register this keyhash to facebook android login settings or wherever you like.
Android: How to get Release Key Hash for facebook for SIGNED app NOT Debug mode
If you have the jks file, then execute this command :
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64
where:
YOUR_RELEASE_KEY_PATH
: PATH to your .jks file
and
YOUR_RELEASE_KEY_ALIAS
: ALIAS NAME you used for making the release APK.
Google Play App Signing - KeyHash Mismatch
I had the same issue and it appears that as you say, the Google Play Store re-signs your apk with a new key, and this what you must provide to Facebook as the key hash (not the one generated using keytool).
The second half of this answer https://stackoverflow.com/a/44448437/2640599 is useful.
Basically you need to provide Facebook with the hash based on the SHA-1 App signing certificate Google generated, instead of using keytool and your local key (which it seems is now just used for uploading to Google).
How to compute key hash for Facebook from deployment_cert.der file?
from SHA-1 hash in hex format (as found in Play console) you can convert it into base64 hash code
example:
echo 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 | xxd -r -p | openssl base64
and then copy generated code to
facebook dev account -> your app -> Basic Steeings -> Android -> Key Hashes
Related Topics
Add a New Item to Recyclerview Programmatically
What Are the Ipc Mechanisms Available in the Android Os
Pass Arraylist Data into Soap Web Service in Android
Ios/Android Cross Platform Development
What Are the Overheads of Using Autoincrement for SQLite on Android
Failure [Install_Failed_Already_Exists] When I Tried to Update My Application
Moving or Copying Data from One Node to Another in Firebase Database
Call Getlayoutinflater() in Places Not in Activity
Android Ble Bluetoothgatt.Writedescriptor() Return Sometimes False
To Draw an Underline Below the Textview in Android
Android Java.Util.Concurrent.Timeunit Convert Milliseconds to Minutes
How to Set Toolbar Text and Back Arrow Color
Can't Put Double Sharedpreferences
Android - Way to Appear Bordered Text on the Textview