我正在开发一个Android应用程序,我想在其中集成一个Facebook 发布功能。我下载了Facebook-Android SDK,然后 readme。Md(文本文件)在那里,其中提到要生成 Android的键散列。我如何生成它?


当前回答

Linux

开放式终端:

用于调试构建

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

你会发现debug。Keystore来自”。Android "文件夹复制并粘贴在桌面上,并运行上述命令

发布版本

keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64

注意:确保在这两种情况下,它必须要求密码。如果它不要求输入密码,则意味着命令中有错误。

其他回答

我犯了一个小错误,应该记住。如果你正在使用你的密钥库,那么给出你的别名,而不是androiddebugkey…

我的问题解决了。现在,如果我的设备上安装了Facebook,那么我的应用程序仍然在Facebook登录集成上获得数据。只关心你的哈希键。

请看下文。

C:\Program Files\Java\jdk1.6.0_45\bin>keytool -exportcert -alias here your alias name  -keystore "G:\yourkeystorename.keystore" |"G:\ssl\bin\openssl" sha1 -binary | "G:\ssl\bin\openssl" base64

然后按Enter -它会要求您输入密码,然后输入您的密钥库密码,而不是Android。

酷。

在Android Studio中也解决了我的问题,但方法略有不同。

在Android Studio中获取SHA-1值。

点击它 点击签署报告 sha - 1副本

SHA-1值是这样的 CD: A1: EA: A3:5C: 5 c: 68: FB:费尔南多-阿隆索:0:6 b: E5:5A: 72:64: DD: 26:8D: 44:84 打开http://tomeko.net/online_tools/hex_to_base64.php进行转换 你的SHA1值到base64。这就是Facebook所要求的 生成的哈希 " ********************= " 并复制关键散列 facebook应用程序控制台。

部分答案来自Github链接

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.os.Bundle;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.text.Editable;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

    Button btn;
    EditText et;
    PackageInfo info;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.button1);
        et=(EditText)findViewById(R.id.editText1);
        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {
                    info = getPackageManager().getPackageInfo("com.example.id", 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()));
                        et.setText("" + something);
                        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());
                }
            }
        });
    }



}

对于Android应用程序

这段代码用于在Android应用程序中获取Facebook集成的哈希键。我已经测试了所有的设备,一切正常。只更改此代码的包名:

private void facebookHashKey() {

    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.app.helpcove", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String hashCode  = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            System.out.println("Print the hashKey for Facebook :"+hashCode);
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
}

以下是步骤

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 Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64 it will ask for password, put android that's all. u will get a key-hash

欲了解更多信息,请访问这里