为什么keytool会生成不同的facebook androiddebugkey哈希? [英] Why keytool is generating different facebook androiddebugkey hash?

查看:87
本文介绍了为什么keytool会生成不同的facebook androiddebugkey哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建使用Facebook登录SDK的Android应用程序.

I am creating Android application which use Facebook login SDK.

我想生成调试键哈希.在Facebook网站上,我找到了以下命令:

I'd like to generate debug key hash. On Facebook website I found this command:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android \ debug.keystore | openssl sha1 -binary |的openssl base64

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | openssl sha1 -binary | openssl base64

我修改了此命令以在我的计算机上工作:

I modified this command to work on my computer:

keytool -exportcert -alias androiddebugkey -keystore C:\ Users \ redio \ .android \ debug.keystore | "C:\ OpenSSL \ bin \ openssl" sha1 -binary |"C:\ OpenSSL \ bin \ openssl" base64

keytool -exportcert -alias androiddebugkey -keystore C:\Users\redio\.android\debug.keystore | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

接下来我输入密码:android

Next I entered password: android

此命令生成此哈希:QUhvjKstiP5gc7hPEzwF89mwHws =

this command generated this hash: QUhvjKstiP5gc7hPEzwF89mwHws=

然后我将其粘贴到Facebook开发者控制台中 而Facebook仍在说密钥哈希无效.我知道我可以复制警告消息中的键哈希,并将其粘贴到Facebook开发人员控制台中.但是我的问题是为什么keytool会生成错误的密钥哈希?

then I pasted it in facebook developer console and facebook is still saying that key hash is invalid. I know that I can copy the key hash from warning message, and paste it in facebook developer console. But my question is why keytool is generating wrong key hash?

推荐答案

在使用keytool生成有效哈希值时,我也遇到了很多问题,但是我实现了下面发现的方法,并且能够注销有效哈希.代码的确切来源尚不清楚,但

I also had a lot of problems getting the keytool to generate a valid hash, but i implemented the method below which i found, and was able to log out a valid hash. The exact origin of the code is a bit unclear, but this blog post is a good guess.

public static String printKeyHash(Activity context) {
    PackageInfo packageInfo;
    String key = null;
    try {
        //getting application package name, as defined in manifest
        String packageName = context.getApplicationContext().getPackageName();

        //Retriving package info
        packageInfo = context.getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES);

        Log.e("Package Name=", context.getApplicationContext().getPackageName());

        for (Signature signature : packageInfo.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            key = new String(Base64.encode(md.digest(), 0));

            // String key = new String(Base64.encodeBytes(md.digest()));
            Log.e("Key Hash=", key);
        }
    } catch (PackageManager.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());
    }

    return key;
}

这篇关于为什么keytool会生成不同的facebook androiddebugkey哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆