我完全不明白这个过程。我已经能够导航到Java SDK中包含keytool的文件夹。虽然我一直得到错误openssl不识别为内部或外部命令。问题是,即使我能让它工作,我该做什么,然后做什么?


当前回答

很容易找到你的android项目的sha1

然后粘贴到这个网站上

对于get sha1只是

// vscode and my cmd
project-name/cd android && ./gradlew signingReport

// other 
project-name/cd android && ./gradlew signingReport

其他回答

在你的应用程序中运行:

FacebookSdk.sdkInitialize(getApplicationContext());
Log.d("AppLog", "key:" + FacebookSdk.getApplicationSignature(this)+"=");

或:

public static void printHashKey(Context context) {
    try {
        final PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
        for (android.content.pm.Signature signature : info.signatures) {
            final MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            final String hashKey = new String(Base64.encode(md.digest(), 0));
            Log.i("AppLog", "key:" + hashKey + "=");
        }
    } catch (Exception e) {
        Log.e("AppLog", "error:", e);
    }
}

然后看看日志。

结果应该以“=”结尾。

解是基于这里和这里。

this will help newbees also. just adding more details to @coder_For_Life22's answer. if this answer helps you don't forget to upvote. it motivates us. for this you must already know the path of the app's keystore file and password for this example consider the key is stored at "c:\keystorekey\new.jks" 1. open this page https://code.google.com/archive/p/openssl-for-windows/downloads 2. download 32 or 64 bit zip file as per your windows OS. 3. extract the downloaded file where ever you want and remember the path. 4. for this example we consider that you have extracted the folder in download folder. so the file address will be "C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe"; 5. now on keyboard press windows+r button. 6. this will open run box. 7. type cmd and press Ctrl+Shift+Enter. 8. this will open command prompt as administrator. 9. here navigate to java's bin folder: if you use jre provided by Android Studio you will find the path as follows: a. open android studio. b. file->project structure c. in the left pane, click 'SDK location' d. in the right pane, below 'JDK location' is your jre path. e. add "\bin" at the end of this path as the file "keytool.exe", we need, is inside this folder. for this example i consider, you have installed java separately and following is the path "C:\Program Files\Java\jre-10.0.2\bin" if you have installed 32bit java it will be in "C:\Program Files (x86)\Java\jre-10.0.2\bin" 10. now with above paths execute command as following:

keytool -exportcert -alias androiddebugkey -keystore "c:\keystorekey\new.jks" | "C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe" sha1 -binary |"C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe" base64

您将被要求输入密码,请输入您在创建密钥存储库密钥时所提供的密码。 ! ! 这将给你钥匙

错误: 如果你得到: --- 'keytool'不能被识别为内部或外部命令 --- 这意味着Java安装在其他地方。

步骤1->在您的系统中打开CMD

步骤2->C:\程序文件\Java\jdk1.6.0_43\bin>

步骤3->keytool -list -v -keystore C:\Users\leon\.android\debug. exeKeystore -alias androiddebugkey -storepass android -keypass android

你得到SHA1值点击这个链接你转换你的SHA1值为哈希键

我100%肯定这个链接会帮助你

keytool -exportcert -alias androiddebugkey -keystore “C:\Users**Deepak**.android\debug.keystore” |“C:\Users\Deepak\ssl\bin\openssl” sha1 -binary |“C:\Users\Deepak\ssl\bin\openssl” base64

2上述命令的变化 1.Deepak===替换为您的系统用户名 2.C:\Users\Deepak\ssl===替换您的Open ssl路径

运行此命令并获得如下输出

C:\Users\Deepak>keytool -exportcert -alias androiddebugkey -keystore "C:\Users\D eepak.android \调试。keystore" | "C:\Users\Deepak\ssl\bin\openssl" sha1 -二进制 | "C:\Users\Deepak\ssl\bin\openssl" base64 输入keystore密码:****** ga0RGNY ******************=

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.hellofacebook", 
                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) {
        
    } catch (NoSuchAlgorithmException e) {
        
    }
    
    ...

保存更改并重新运行示例。检查你的logcat输出是否有类似这样的消息:

D/KeyHash:(936): 478uEnKQV+fMQT8Dy4AKvHkYibo=

将密钥哈希保存在开发人员配置文件中。重新运行示例并验证可以成功登录。