How to generate Keyhash (Facebook) using Keytool in android for W7 32bit

I tried to create Keyhash to integrate Facebook into our application, but when I generated keyhash through the cmd hint, it cannot generate.

C:\Users\DON\.android>keytool -exportcert -alias androiddebugkey -keystore ~/.an droid/debug.keystore | openssl sha1 -binary | openssl base64 

'keytool' is not recognized as an internal or external command, operating program, or batch file.

and another command that I use:

 C:\Program Files\Java\jdk1.6.0_20\bin>keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 

'openssl' is not recognized as an internal or external command, operating program, or batch file.

What is the problem?

+8
source share
5 answers

Using this command, first download this http://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8k_WIN32.zip file. Then extract the file and run this command:

 C:\Program Files\Java\jdk1.6.0_20\bin>keytool -export -alias myAlias -keystore C:\Users\DON\.android\myKeyStore | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl enc -a -xtIm30l*********= 

DON is my system name and should be replaced by your system name.

+12
source
  • Download the openssl-for-windows package.
  • Remove the zip.
  • In windows, edit the system path variable that points to <openssl-extracted-folder>/bin
  • Then run the command.
+9
source

First configure Facebook sdk and then the main program, if you add this, you will get keyhash on the console

There will be chances that 3 types of keys are debugged once, and the other is the release key, and after downloading the signature with google changes you can provide all these 3 keys for the facebook developer account, after which you can check the facebook login. depending on your application mode facebook will match the key. Use a toast to see keyhash if you don't know the Android monitor from Android studio.

 import com.facebook.FacebookSdk; import com.facebook.appevents.AppEventsLogger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); printKeyHash(); } private void printKeyHash() { try { PackageInfo info = getPackageManager().getPackageInfo( getPackageName(), 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 (PackageManager.NameNotFoundException e) { Log.e("jk", "Exception(NameNotFoundException) : " + e); } catch (NoSuchAlgorithmException e) { Log.e("mkm", "Exception(NoSuchAlgorithmException) : " + e); } } 

}

+4
source

this is a late answer, but it will help lazy people like me .. add this code to your application class, there is no need to load openssl and no need to set the path .. just need to just copy my code .. and keyHash will be generated in the log.

 import com.facebook.FacebookSdk; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); printKeyHash(); } private void printKeyHash() { try { PackageInfo info = getPackageManager().getPackageInfo( getPackageName(), 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 (PackageManager.NameNotFoundException e) { Log.e("jk", "Exception(NameNotFoundException) : " + e); } catch (NoSuchAlgorithmException e) { Log.e("mkm", "Exception(NoSuchAlgorithmException) : " + e); } } } 

and don't forget to add the MyApplication class to the manifest:

 <application android:name=".application.MyApplication" </application> 
+2
source

Download openssl from https://code.google.com/archive/p/openssl-for-windows/downloads .

Extract the file and then run in CMD, re-planning routes and KeyName

 keytool -exportcert -alias KEYNAME -keystore "C:\Users\YOUR_USER\.android\debug.keystore" | "C:\URL_OPENSSL_EXTRACTED\bin\openssl" sha1 -binary | "C:\URL_OPENSSL_EXTRACTED\bin\openssl" base64. 
0
source

All Articles