我希望为我的应用程序生成一个应用程序签名,以后将与Facebook集成。在Facebook的一个教程中,我发现了这个命令:

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

在教程中,它说通过运行这个cmd,我的生成签名的进程将开始。

但是,这个命令会给出一个错误:

openssl is not recognized as an internal or external command

我怎样才能摆脱这个?


当前回答

这是一个很晚的答案,但它将帮助像我这样的懒人。将此代码添加到你的Application类中,不需要下载openssl,也不需要设置路径。只需要复制这个代码..和keyHash将在日志中生成。

import com.facebook.FacebookSdk;
public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
        printKeyHash();
    }

    private void printKeyHash() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.i("KeyHash:",
                        Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("jk", "Exception(NameNotFoundException) : " + e);
        } catch (NoSuchAlgorithmException e) {
            Log.e("mkm", "Exception(NoSuchAlgorithmException) : " + e);
        }
    }
}

不要忘记在manifest中添加MyApplication类:

<application
        android:name=".MyApplication"
</application>

其他回答

请遵循以下步骤,我希望你的钥匙工作正常:

Step 1 You will need OpenSSL. You can download the binary from openssl-for-windows project on Google Code. Step 2 Unzip the folder, then copy the path to the bin folder to the clipboard. For example, if the file is unzipped to the location C:\Users\gaurav\openssl-0.9.8k_WIN32, then copy the path C:\Users\gaurav\openssl-0.9.8k_WIN32\bin. Step 3 Add the path to your system environment path. After your PATH environment variable is set, open the cmd and type this command: C:\>keytool -exportcert -alias androiddebugkey -keystore [path to debug.keystore] | openssl sha1 -binary | openssl base64 Type your password when prompted. If the command works, then you will be shown a key.

如果你在本地安装了git,很容易解决。 你可以打开git bash,在你想要生成密钥的地方更改目录,然后运行你的命令。 它将工作,因为git默认安装开放的SSL exe,你不需要每次你想运行SSL exe手动设置路径。 它对我很有效,我希望它能有所帮助。

对于Windows用户,请从谷歌的代码存储库https://code.google.com/p/openssl-for-windows/downloads/list下载开放SSL

下载后,将内容解压到一个文件夹中,最好是在c:驱动器中。

然后更新PATH环境变量,以便可以从命令行中的任何位置使用.exe。

要更新PATH环境变量,请单击“我的电脑->属性->高级系统设置”。

单击高级选项卡,单击对话框底部的“环境变量”按钮,然后单击编辑从“系统变量”部分选择路径条目。

将该路径粘贴到解压缩的openssl下载的bin文件夹,然后单击ok。

您将需要关闭和打开之前可能启动的命令提示符,以便加载更新后的路径设置。

现在运行这个命令:

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Oladipo.android\debug. keystoreKeystore " | openssl sha1 -binary | openssl base64 . Keystore

您应该看到开发人员键。

我使用了下面的代码:

这对我来说很成功。

"C:\Program Files\Java\jdk1.6.0_26\bin\keytool.exe" -exportcert -alias sociallisting -
keystore "D:\keystore\SocialListing" | "C:\cygwin\bin\openssl.exe" sha1 -binary | 
"C:\cygwin\bin\openssl.exe" base64

我今天也遇到了同样的问题,通过以下视频(SSL安装)解决了它- https://www.youtube.com/watch?v=PoAc1lpfK8I&ab_channel=GleyGames

然后,我使用Usamas命令,并运行它(在命令中更改路径后),我从java安装中的bin文件夹中运行它,使用CMD。

对我有效的全面命令:

(来自C:\Program Files\Java\ jdk-11.0.12\bin):

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "C:\Program Files\OpenSSL-Win64\bin\openssl" sha1 -binary | "C:\Program Files\OpenSSL-Win64\bin\openssl" base64