我正在开发一个Android应用程序,我想在其中集成一个Facebook 发布功能。我下载了Facebook-Android SDK,然后 readme。Md(文本文件)在那里,其中提到要生成 Android的键散列。我如何生成它?
当前回答
使用它在kotlin中打印键哈希
try {
val info = context.getPackageManager().getPackageInfo(context.packageName,
PackageManager.GET_SIGNATURES);
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
Log.d("Key hash ", android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT))
}
}catch (e:Exception){
}
其他回答
在一个类似的问题上,我发现这对我很有效:
将你想知道散列值的apkname.apk文件复制到“Java\jdk1.7.0_79\bin”文件夹中 执行keytool -list -printcert -jarfile apkname.apk 复制SHA1值并使用此站点进行转换 使用转换后的Keyhash值(例如:zaHqo1xcaPv6CmvlWnJk3SaNRIQ=)
有两种方法可供选择,一种是复杂的,一种是简单的
方法一:(小复杂)
首先,你必须下载相应的64位或32位ssl,记住下载版本号openssl-0.9.8e_X64.zip或openssl-0.9.8e_WIN32.zip后面有e的文件,而不是版本号后面有k的文件,
并放置在AndroidStudio/jre/bin目录下,如果你不知道放在哪里,你可以通过右键单击android studio快捷方式找到这个目录:
现在您已经在一个地方管理了两个必需的东西,但是仍然需要找到调试的路径。在“C:\Users\yourusernamehere\.android\debug.keystore”中可以找到。
如果您的应用程序已经发布或即将发布,那么当且仅当您正在测试时,请使用您的发布签名密钥库 在开发模式下可以使用调试、按键
一切都设置好后,让我们以base64格式安排您想要执行的用于生成哈希键的命令,您的命令将如下所示
keytool.exe -exportcert -alias androiddebugkey -keystore "C:\Users\ayyaz talat\.android\debug.keystore" | "D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" sha1 -binary |"D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" base64
它将提示您为调试输入密码。密钥存储库,默认为android。如果您使用自己的密钥,那么密码也将是您的。 如果一切顺利,输出将如下所示,希望对您有所帮助
第二种方法(分别为简单方法)
如果你不想经历以上所有的过程,那么只需使用下面的方法来记录haskey:
private void printKeyHash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("KeyHash:", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", e.toString());
}
}
输出:
1)创建一个密钥来签署您的应用程序,并记住别名。 2)安装OpenSSL。 3)将OpenSSL的bin文件夹放在您的路径中。 4)按照FB-Android-SDK页面上“设置单点登录”中提到的步骤,生成您的哈希密钥。确保您输入了正确的别名和密钥库文件名。 5)在facebook上创建一个应用程序,在移动设备选项卡下,输入这个哈希密钥。
这是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页面。
以下是步骤
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
欲了解更多信息,请访问这里
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- 如何测试Facebook本地连接
- 我如何找到哪个程序正在使用端口80在Windows?
- 在Windows中有像GREP这样的模式匹配实用程序吗?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- 如何在iOS中使用Swift编程segue
- 如何在Windows命令提示符下运行.sh ?