I have a requirement where i need to find the APK Cert sha256 . I am able to find the SHA1 and MD5 using signing report in android studio. But i could not find SHA256 cert. How can i find that.
use this method:
//HashKey Generator
public static String getProjectHashKey(Context context) {
String hashKey = "";
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
context.getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
hashKey = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.d("KeyHash:", hashKey);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return hashKey;
}
Related
I am getting the "Invalid key hash" error on my Android even though my app is in production and the facebook app is set as public. If I put the key hash into the facebook settings it works fine, but I suppose this would only work on my own device. What am I getting wrong here?
You have to create a release apk and print keyhash using this method. and set that keyHash in fb consol.
public static void printHashKey(Context context)
{
// Add code to print out the key hash
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
com.example.app.BuildConfig.APPLICATION_ID,
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
Follow this steps for solution.
Paste this code in your activity.
public static void printHashKey(Context context)
{
// Add code to print out the key hash
try
{
PackageInfo info = context.getPackageManager().getPackageInfo( com.example.app.BuildConfig.APPLICATION_ID, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures)
{
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
}
Sign your APK.(release APK)
Install generated signed APK to your mobile
Connect your phone with pc.
Now open screen where you put above code.
Here your can see new HashKey in logcat
Paste this HashKey in Facebook developer site where you app created.
Enjoy with your application.
At the bottom of this facebook developers troubleshooting link a code is provided.
What do I do with the code to get the key hash?
below is the code provided by Facebook
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.loginhowto",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...
You need to copy the code to one of your activities and run the app. You will get the HashKey in Android Logcat.
You can copy the HashKey from Logcat and post in Facebook's Developer Console of the app.
I have this problem, I create FB login with FB SDK Android with java in Eclipse. When i debug and run this app in Android Emulator all is correct, i can login i can logout. But when i export app to develop version (.apk), and install it at my phone or at genymotion emulator i geting this errors:
"Invlaid key hash. The key hash xxxxxxxxxxxxxxxxxxx does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/72012084472886"
The hash key is create correoct i use this:
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
Do you have some idea, what is wrong?
Thank you .
When you run an app via ADB Eclipse usually uses a keystore named debug.keystore, this keystore is usually the one you don't use on production apps. When you export your app and create a keystore, the keyhash will change value because you change keystore.
You can implement this code to your app so you can echo the keyhash to you stackrace:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageInfo(pContext, 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);
}
}
The snippet is only suitable for development, not for production!
login with Facebook
how can I assign a "Development Key Hash" to a android device?
using KeyTools
keytool -importkeystore -srckeystore path/to/keystore/with/forgotten/pw -destkeystore path/to/my/new/keystore
I sign only the application using the emulator and not device
how can I fix it?
You can get the key hash for that device with this snippet, just add the code in your MainActivity and check the Logcat.
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
BR
I'm trying to generate key hash code for android on (Windows 8.1 PRO 64x) according to these steps Android key hash for Facebook App. I did it before and worked well but was for windows 8, now I followed all the steps and the hash code I got was this.
Any suggestions how to solve it or what is this ??
You can have your hash in a easier way, like in the offical Facebook's documentation.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...
}