Facebook Android SDK 的密钥哈希

发布于 2024-10-06 02:04:23 字数 276 浏览 0 评论 0原文

我不知道如何获取使用 Facebook Android SDK 所需的密钥哈希。我发现我可以将 keytool 与这些命令一起使用:

  keytool -exportcert -alias [alias]
 -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e

唯一的问题是我不知道在哪里插入它,我尝试通过命令窗口(win7)并尝试打开文件 keytool.exe 。

I can't figure out how to get the Key Hash required to use the Facebook Android SDK. I figured out that I can use keytool with these commands:

  keytool -exportcert -alias [alias]
 -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e

The only problem is that I have no idea where to insert this, I tried through command windows (win7) and I tried opening the file keytool.exe.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

时光沙漏 2024-10-13 02:04:23

您可以从此处安装 Open SSL,这将使您的命令正常工作

You can install Open SSL from here , that should make your command work

红颜悴 2024-10-13 02:04:23

我创建了一个批处理脚本 facebookkeydebug.bat,它返回所需的 Facebook 密钥哈希值。只需编辑脚本,设置正确的路径、密钥库名称并运行它。

:: Getting Android key hash for Facebook app on Windows
:: Requirement: OpenSSL for Windows (http://code.google.com/p/openssl-for-windows/downloads/list)
:: Usage: set paths and run facebookkeydebug.bat

@echo Exporting keystore cert
keytool -exportcert -alias androiddebugkey -keystore C:\Users\myusername\.android\debug.keystore -storepass android -keypass android > debug.keystore.bin

@echo Converting to sha1
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl sha1 -binary debug.keystore.bin > debug.keystore.sha1

@echo Converting to base64
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1 -out debug.keystore.base64

@echo Done, Android hash key for Facebook app is:
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1
@pause

编辑:我发布了一个存储库,其中包含一些批处理脚本,用于在 Windows 上签名和获取证书密钥: https://github.com/petrnohejl/Android -脚本

I created a batch script facebookkeydebug.bat, which return desired Facebook key hash. Just edit the script, set correct paths, keystore name and run it.

:: Getting Android key hash for Facebook app on Windows
:: Requirement: OpenSSL for Windows (http://code.google.com/p/openssl-for-windows/downloads/list)
:: Usage: set paths and run facebookkeydebug.bat

@echo Exporting keystore cert
keytool -exportcert -alias androiddebugkey -keystore C:\Users\myusername\.android\debug.keystore -storepass android -keypass android > debug.keystore.bin

@echo Converting to sha1
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl sha1 -binary debug.keystore.bin > debug.keystore.sha1

@echo Converting to base64
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1 -out debug.keystore.base64

@echo Done, Android hash key for Facebook app is:
C:\PROGRAMS\openssl-0.9.8k_X64\bin\openssl base64 -in debug.keystore.sha1
@pause

EDIT: I published a repo with some batch scripts for signing and getting cert keys on Windows: https://github.com/petrnohejl/Android-Scripts

醉生梦死 2024-10-13 02:04:23
  1. 基于 Windows 从 http://slproweb.com/products/Win32OpenSSL.html 下载并安装 OpenSSL 32 或 64 位。(注意:也可以从该站点下载并安装第一个可重新发行的 Visual C++ 208)
  2. 将已安装的 OpenSSL 的 bin 目录放入 Windows 路径中。
  3. 打开命令提示符并转到 C:\Users{User_Name}.android
  4. 现在将此命令放在 cmd 上“keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64” .(请参阅https://developers.facebook.com/docs/android/getting-开始#samples
  5. 现在输入密码“facebook”,不带双引号。
  6. 现在将生成一个哈希密钥
    在此处输入图像描述
  7. 最后转到 Facebook 开发者网站。确保您已登录 Facebook,然后使用右上角的下拉菜单转到“开发人员设置”:
  8. 进入开发人员设置后,从左侧导航中选择“示例应用程序”,然后添加并将您的密钥哈希保存到您的个人资料中:
    在此处输入图像描述
  1. Download and install OpenSSL from http://slproweb.com/products/Win32OpenSSL.html based on windows 32 or 64 bit.(Note: Download and install first visual C++ 208 redisributable from that site also )
  2. Put the bin directory of installed OpenSSL in windows path.
  3. Open the command prompt and go to C:\Users{User_Name}.android
  4. now put this command on cmd "keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64".(refer https://developers.facebook.com/docs/android/getting-started#samples)
  5. Now enter password "facebook" without double quote.
  6. Now a hash key will be generated
    enter image description here
  7. Finally go to the Facebook Developer site. Make sure you are logged into Facebook and, using the dropdown menu in the top-right, go to your 'Developer Settings':
  8. Once you're in your developer settings, select 'Sample App' from the navigation on the left, and add and save your key hash into your profile:
    enter image description here
爱情眠于流年 2024-10-13 02:04:23

您可以使用下面的代码来获取哈希密钥:

try {

   PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 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) {
   Log.e("name not found", e.toString());
  } catch (NoSuchAlgorithmException e) {
   Log.e("no such an algorithm", e.toString());
  }

参考:

http ://limbaniandroid.blogspot.com/2013/04/how-to-get-hash-key-for-integarte.html

you can use code below to get the Hash key :

try {

   PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 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) {
   Log.e("name not found", e.toString());
  } catch (NoSuchAlgorithmException e) {
   Log.e("no such an algorithm", e.toString());
  }

Reference :

http://limbaniandroid.blogspot.com/2013/04/how-to-get-hash-key-for-integarte.html

花桑 2024-10-13 02:04:23

为了让事情变得更容易 -

keytool.exe -list -alias androiddebugkey -keystore debug.keystore -v

这应该为您提供所需的指纹,而无需安装 openssl 的麻烦。

例如

Certificate fingerprints:
         MD5:  1A:5E:AA:CB:1A:CF:68:F0:8B:DA:D8:BC:EE:4F:BF:EE
         SHA1: D2:89:D1:5A:BC:F8:E3:E5:62:4D:DD:20:DD:96:CD:AB:51:A1:C1:7F
         Signature algorithm name: SHA1withRSA
         Version: 3

To make things easier -

keytool.exe -list -alias androiddebugkey -keystore debug.keystore -v

this should provide you with the fingerprints needed, without the hassle of installing openssl.

e.g.

Certificate fingerprints:
         MD5:  1A:5E:AA:CB:1A:CF:68:F0:8B:DA:D8:BC:EE:4F:BF:EE
         SHA1: D2:89:D1:5A:BC:F8:E3:E5:62:4D:DD:20:DD:96:CD:AB:51:A1:C1:7F
         Signature algorithm name: SHA1withRSA
         Version: 3
往事随风而去 2024-10-13 02:04:23

这是如何从密钥库获取密钥哈希的示例:

首先我们需要获取以下路径:

Java 路径:
C:\Program Files\Java\jdk1.6.0_35\jre\bin

打开 SSL 路径:
C:\OpenSSL-Win32\bin

(从以下位置安装:http://www.openssl.org/

密钥库路径:
C:\Data\ANDROID\KEYSTORE\

2) 然后转到命令行并键入:

cd [Java 路径]

3) 然后输入:

keytool.exe -exportcert -alias [别名] -keystore [密钥库
路径]\debug.keystore | [打开 SSL 路径]\openssl sha1 -binary | [打开
SSL 路径]\bin\openssl base64

4) 必须需要您的密钥库的密码,然后您就有与您的 Android 密钥库相关的 Hash Key

在此处输入图像描述

这是有关如何为 设置密钥哈希 的文档Facebook

https://developers.facebook。 com/docs/android/getting-started#release-key-hash

This is an example of how to get the Key Hash from the Keystore:

first we need to get the paths of:

Java path:
C:\Program Files\Java\jdk1.6.0_35\jre\bin

Open SSL Path:
C:\OpenSSL-Win32\bin

(install from: http://www.openssl.org/)

Keystore Path:
C:\Data\ANDROID\KEYSTORE\

2) then go to Command line and type:

cd [Java path]

3) then type :

keytool.exe -exportcert -alias [alias name] -keystore [Keystore
Path]\debug.keystore | [Open SSL Path]\openssl sha1 -binary | [Open
SSL Path]\bin\openssl base64

4) the password of your Keystore must be required and then you have the Hash Key related to your Android Keystore.

enter image description here

This is the doc of how to set the Key Hash for Facebook:

https://developers.facebook.com/docs/android/getting-started#release-key-hash

海未深 2024-10-13 02:04:23

您必须打开命令提示符窗口。转到开始->运行并输入“cmd”并按 Enter 键。然后,您必须导航到 keytool 所在的文件夹(除非它在您的路径中),然后键入该命令。

也就是说,假设该命令适用于 Windows 而不是 Linux。

You have to open a command prompt window. Go to start->run and type 'cmd' and hit enter. Then you have to navigate to the folder where keytool is (unless it's in your path), and then type that command.

That is, assuming that command is for windows and not linux.

桃酥萝莉 2024-10-13 02:04:23

最好的方法是使用代码生成 Key-Hash:

 public static void generateKeyHash(Context context) {
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(
                "com.example.user2.testapp",
                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) {

    } catch (NoSuchAlgorithmException e) {

    }
}

调用此方法一次并生成 key-hash,享受

Best way is to generate Key-Hash using code:

 public static void generateKeyHash(Context context) {
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(
                "com.example.user2.testapp",
                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) {

    } catch (NoSuchAlgorithmException e) {

    }
}

call this method once and generate key-hash, enjoy

亣腦蒛氧 2024-10-13 02:04:23

C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe -exportcert -alias "typeYouraliasname" -keystore 密钥库位置 | C:\OpenSSL-Win32\bin\openssl sha1 -binary | C:\OpenSSL-Win32\bin\openssl base64

C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe -exportcert -alias "typeYouraliasname" -keystore locationof your keystore | C:\OpenSSL-Win32\bin\openssl sha1 -binary | C:\OpenSSL-Win32\bin\openssl base64

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文