Key hash for Android
I'm working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the readme.md (text file) in there, in which it is mentioned to generate the key hash for Android. How do I generate it?
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 SettingsAdministrator.androiddebug.keystore" | "C:OpenSSLbinopenssl" sha1 -binary |"C:OpenSSLbinopenssl" base64
For more info visit here
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. :)
链接地址: http://www.djcxy.com/p/59626.html上一篇: 如何更改Android SDK路径
下一篇: Android的关键哈希