How to create Android Facebook Key Hash?
Please try this:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
You can simply use one line javascript in browser console to convert a hex map key to base64. Open console in latest browser (F12 on Windows, ⌥ Option+⌘ Command+I on macOS, Ctrl+⇧ Shift+I on Linux) and paste the code and replace the SHA-1
, SHA-256
hex map that Google Play provides under Release 𡪠Setup 𡪠App signing:
Hex map key to Base64 key hash
> btoa('a7:77:d9:20:c8:01:dd:fa:2c:3b:db:b2:ef:c5:5a:1d:ae:f7:28:6f'.split(':').map(hc => String.fromCharCode(parseInt(hc, 16))).join(''))
< "p3fZIMgB3fosO9uy78VaHa73KG8="
You can also convert it here; run the below code snippet and paste hex map key and hit convert button:
document.getElementById('convert').addEventListener('click', function() {
document.getElementById('result').textContent = btoa(
document.getElementById('hex-map').value
.split(':')
.map(hc => String.fromCharCode(parseInt(hc, 16)))
.join('')
);
});
<textarea id="hex-map" placeholder="paste hex key map here" style="width: 100%"></textarea>
<button id="convert">Convert</button>
<p><code id="result"></code></p>
And if you want to reverse a key hash to check and validate it:
Reverse Base64 key hash to hex map key
> atob('p3fZIMgB3fosO9uy78VaHa73KG8=').split('').map(c => c.charCodeAt(0).toString(16)).join(':')
< "a7:77:d9:20:c8:1:dd:fa:2c:3b:db:b2:ef:c5:5a:1d:ae:f7:28:6f"
document.getElementById('convert').addEventListener('click', function() {
document.getElementById('result').textContent = atob(document.getElementById('base64-hash').value)
.split('')
.map(c => c.charCodeAt(0).toString(16))
.join(':')
});
<textarea id="base64-hash" placeholder="paste base64 key hash here" style="width: 100%"></textarea>
<button id="convert">Convert</button>
<p><code id="result"></code></p>
For Linux and Mac
Open Terminal :
For Debug Build
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
You will find debug.keystore in the ".android" folder. Copy it and paste onto the desktop and run the above command.
For release Build
keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64
NOTE : Make sure that in both cases it asks for a password. If it does not ask for a password, it means that something is wrong in the command. Password for debug.keystore is "android" and for release you have to enter password that you set during create keystore.
Here is what you need to do -
Download openSSl from Code 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