I want to add log in with Facebook button to my application. So i tried to follow this guide.
Getting Started with the Facebook SDK for Android
I tried to get Android key hash. But i couldn't to run it on my PC cmd.
This is code i tried.
i added my home path to this %HOMEPATH%
.
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
But it shows like this error.
Can anyone help me to fix this error.
Firstly download openssl from this a link
Second extract it to Local disk C: name it openssl i.e folder name
third set it in Environment variables. procedure as follows
right click on My computer->properties->advanced->environment variables
under system variables->click on path and click edit
Now insert a ';' semi-colon and paste the path of folder openssl. then ok.
now u can see openssl is recognized as command in cmd.
to get KeyHash execute follwing cmd
keytool -exportcert -alias androiddebugkey -keystore "path of ur debug.keystore" | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
Solution for the warning---
WARNING: can't open config file: C:/OpenSSL/openssl.cnf
WARNING: can't open config file: C:/OpenSSL/openssl.cnf
openssl:Error: 'base' is an invalid command.
1st add below line in environment variable as similar to third step.
set OPENSSL_CONF=c:\openssl\bin\openssl.cfg
now run above cmd
keytool -exportcert -alias androiddebugkey -keystore "path of ur debug.keystore" | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
u do get warning but keyHash is returned in cmd...
Use following code to print hash key in your log
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PrintHashKeyInLog();
}
public void PrintHashKeyInLog() {
PackageInfo info;
try {
info = getPackageManager().getPackageInfo(
"Your package 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.encode(md.digest(), 0));
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());
}
}