我不知道如何获得使用 Facebook Android SDK 所需的密钥哈希。我发现我可以使用keytool
这些命令:
keytool -exportcert -alias [alias]
-keystore [keystore] | openssl sha1 -binary | openssl enc -a -e
唯一的问题是我不知道在哪里插入它,我尝试通过命令窗口(win7)并尝试打开文件 keytool.exe。
您可以从此处安装 Open SSL ,这应该可以使您的命令正常工作
我创建了一个批处理脚本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-Scripts
您可以使用下面的代码来获取哈希键:
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
为了让事情变得更容易 -
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
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.
Key Hash
for Facebook
:https://developers.facebook.com/docs/android/getting-started#release-key-hash
您必须打开命令提示符窗口。转到开始->运行并键入“cmd”并按回车键。然后您必须导航到所在的文件夹keytool
(除非它在您的路径中),然后键入该命令。
也就是说,假设该命令适用于 windows 而不是 linux。
最好的方法是使用代码生成 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,享受
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