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


当前回答

以下是步骤

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

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

其他回答

在Android Studio中,只需点击右侧侧边栏面板“Gradle”即可显示gardel面板: -YOURAPPNAME ——任务 ——安卓 ----(双击)signingReport(启动Gradle Daemon)

然后你会看到结果:

Config: debug
Store: C:\Users\username\.android\debug.keystore
Alias: AndroidDebugKey
MD5: C8:46:01:EA:36:02:D1:21:1B:23:19:91:D4:32:CB:AC
SHA1: 38:AB:4C:01:01:D7:62:E0:61:D1:9F:52:04:0C:E5:07:4E:E4:9B:39
SHA-256: 1B:8C:DC:35:48:10:01:2C:1F:BD:01:64:F1:01:06:01:60:01:A6:8B:10:15:2E:BF:7B:C4:FD:38:4C:C1:74:01
Valid until: Saturday, February 12, 2050

SHA1副本:

38:AB:4C:01:01:D7:62:E0:68:D1:9F:52:04:0C:E5:07:4E:E4:9B:39

进入本页

粘贴SHA1并生成您的Facebook密钥哈希代码。

我已经这样做了Linux操作系统和Windows操作系统:

Linux:

下载Openssl 打开终端 keytool -exportcert -alias **myaliasname** -keystore **/home/comp-1/Desktop/mykeystore. xmlJks ** | openssl sha1 -binary | openssl base64

请更改别名和Keystore与它的路径作为您的要求。

终端将询问密钥库的密码。您必须为相同的密钥存储库提供密码。

最后你会得到Release Hashkey。

窗口:

释放Hashkey的步骤:

下载Openssl(从这里下载),我已经下载了64位操作系统,你可以在这里找到更多 解压下载的zip文件到C:只\驱动器 打开命令提示符 "C:\Users\hiren.patel\Desktop\mykeystore. keytool -exportcert -alias **myaliasname** -keystore **"\openssl-0.9.8e_X64\bin\openssl.exe" sha1 -二进制| "C:\openssl-0.9.8e_X64\bin\openssl.exe" base64

请更改别名和Keystore与它的路径作为您的要求。

注意:请将您的详细信息放在我标记的** **之间。

终端将询问密钥库的密码。您必须为相同的密钥存储库提供密码。

最后你会得到Release Hashkey。

Done

这是Facebook官方页面上给出的内容:

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

让我把这个命令分解成几个片段。

Look for "keytool.exe". You can search that on the C: drive. You can find it in "java jdk" or "java jre". If you have installed multiple versions, choose any. Open a CMD prompt and go to the above directory where you found "keytool.exe". Clip the "exe`" and paste the above command provided on the Facebook page. You will get an error on entering this that OpenSSL is not recognized as in input output command. Solution : Download "Openssl" from OpenSSL (if you have a 64-bit machine you must download openssl-0.9.8e X64). Extract and save it anywhere... I saved it on the C: drive in the OpenSSl folder Replace the openssl in the above command in which you was getting an error of OpenSSL with "C:\OpenSSL\bin\openssl" at both the places after the pipe, "|". If prompted for a password, enter android.

你会得到你的哈希键。要了解进一步的步骤,请再次参考Facebook页面。

我只是为这个确切的目的做了一个工具,即https://keyhash.vaibhavpandey.com/。它比其他任何方法都简单,因为它需要您浏览计算机上的密钥存储库,并输入密码,分别为谷歌和Facebook生成SHA-1十六进制和Base64版本。

不必担心密钥库或密码短语,因为工作完全是在浏览器中完成的,您可以检查网络选项卡,该工具也是开源的https://github.com/vaibhavpandeyvpz/keyhash。

你可以从Java/Kotlin Activity中打印哈希键。部分代码已弃用,但这里是包含新旧代码的完整解决方案。

private fun printHashKey(context: Context) {
    try {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            val packageInfo: PackageInfo = context.packageManager.getPackageInfo(
                context.packageName,
                PackageManager.GET_SIGNING_CERTIFICATES
            )

            for (signature in packageInfo.signingInfo.apkContentsSigners) {
                val md = MessageDigest.getInstance("SHA")
                md.update(signature.toByteArray())
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
            }
        } else {
            val packageInfo: PackageInfo = context.packageManager.getPackageInfo(
                context.packageName,
                PackageManager.GET_SIGNATURES
            )

            for (signature in packageInfo.signatures) {
                val md = MessageDigest.getInstance("SHA")
                md.update(signature.toByteArray())
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT))
            }
        }

    } catch (e: PackageManager.NameNotFoundException) {
        Log.d(TAG, "printHashKey: PackageManager.NameNotFoundException -> $e")
    } catch (e: NoSuchAlgorithmException) {
        Log.d(TAG, "printHashKey: NoSuchAlgorithmException -> $e")
    }
}