Khurram W. Malik
Khurram W. Malik

Reputation: 2895

Openssl is not recognized as an internal or external command

I wish to generate an application signature for my app which will later be integrated with Facebook. In one of Facebook's tutorials, I found this command:

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

In the tutorial, it says that by running this cmd, my process of generating the signature will start.

However, this command gives an error:

openssl is not recognized as an internal or external command

How can I get rid of this?

Upvotes: 235

Views: 389130

Answers (24)

HybrisHelp
HybrisHelp

Reputation: 5810

If you are on Windows and have git installed then you can run the open ssl command using GIT Bash.

  1. Go to the directory where you want to store the key

  2. Right-click and open the GIT Bash

  3. Here you can run any openssl command. e.g.

    openssl enc -aes-128-cbc -k test -P -md sha1

Upvotes: 15

Buraxta
Buraxta

Reputation: 61

If you're using Windows and have Git Bash installed, you can resolve this issue by running the command in Git Bash. Here's how you can do it:

  1. Open Git Bash.

  2. Navigate to the directory where you want to generate the application signature.

  3. Run the following command:

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

You may need these as well:

  • Make sure you have installed Git Bash on your Windows system. You can download it from the official Git website: https://git-scm.com/download/win

  • Ensure that you're running the command in the correct directory. If you're not sure, you can use the pwd command to check the current working directory.

Upvotes: 0

Anuj Kaithwas
Anuj Kaithwas

Reputation: 842

So I tried almost everything that was mentioned as a solution here but that didn't work for me. If you are on windows and have Git installed, just do the below and you will get it in a sec;

1. Open Git Bash
2.keytool -exportcert -alias authFB -keystore "c:\users\your name\.android\debug.keystore" | "C:\Program Files\Git\usr\bin\openssl.exe" sha1 -binary | "C:\Program Files\Git\usr\bin\openssl.exe" base64

enter image description here

Upvotes: 0

Mr.B
Mr.B

Reputation: 3787

Easy solution if you have git installed locally. you can just open git bash, change directory where you want your keys will be generated and then run your command. it will work because git installs open ssl exe by default and your don't need to set path to your ssl exe manually each time you want to run it. it works for me and I hope it helps.

Upvotes: 0

Deepak Singh
Deepak Singh

Reputation: 1145

use this

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | "C:\Users\DK\openssl-0.9.8d_X64\bin\openssl.exe" sha1 -binary | "C:\Users\DK\openssl-0.9.8d_X64\bin\openssl.exe" base64

Upvotes: 0

Julian Paul
Julian Paul

Reputation: 182

Step 1

Download SSL for windows at https://code.google.com/archive/p/openssl-for-windows/downloads.

Step 2

Unzip the folder to OpenSSL and paste it to "C:\Program Files".

Step 3

Add "C:\Program Files\OpenSSL\bin" to your environnement variables (Edit the system environnement variables > Environnement variables > Path > New). It will make openssl work in the terminal.

Step 4

Add "C:\Program Files\Android\Android Studio\jre\bin" to your environnement variables. It will make keytool work in the terminal.

Step 5

Open a terminal and execute :

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

The password should be android.

Upvotes: 0

Usama Sarwar
Usama Sarwar

Reputation: 9020

Well at the place of OpenSSL ... you have to put actually the path to your OpenSSL folder that you have downloaded. Your actual command should look like this:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | "C:\Users\abc\openssl\bin\openssl.exe" sha1 -binary | "C:\Users\abc\openssl\bin\openssl.exe" base64

Remember, the path that you will enter will be the path where you have installed the OpenSSL.

Edit:

you can download OpenSSL for windows 32 and 64 bit from the respective links below:

OpenSSL for 64 Bits

OpenSSL for 32 Bits

Upvotes: 445

Slava Bugz
Slava Bugz

Reputation: 448

I've got the same issue today, solved it by following this video (the SSL installation) - https://www.youtube.com/watch?v=PoAc1lpfK8I&ab_channel=GleyGames

Then, i've took Usamas command, and run it (after changing the paths in the command), I've run it FROM inside the bin folder inside the java installation, using CMD.

full command that worked for me:

(from inside 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

Upvotes: 0

Marcos Silva
Marcos Silva

Reputation: 69

For those who arrive lost as I was now, follow Usama Sarwar response but if:

"your_openssl_path/bin/openssl.exe"

doesn't work, try it

your_openssl_path/bin/openssl.exe.

Without the quotes.

"c:\openssl\bin\openssl.exe" => Didn't work for me

c:\openssl\bin\openssl.exe => Worked for me

Upvotes: 0

fuse
fuse

Reputation: 71

IDK if this is relevant here, but if you have Git Installed, you can find the openssl in the "C:\Program Files\Git\usr\bin" and that location you can use in the Terminal for your Keystore Command.

oh and yeah the command:

keytool -exportcert -alias keystore -keystore "C:\Users\YOURPATH/filename.jks" | "C:\Program Files\Git\usr\bin\openssl" sha1 -binary | "C:\Program Files\Git\usr\bin\openssl" base64

Upvotes: 3

Sagar Chavada
Sagar Chavada

Reputation: 5269

it's late answer but it will help to lazy people like me.. add this code to your Application class, there is no need to download openssl and no need to set the path.. only need is just copy this code.. and keyHash will generated in log.

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);
        }
    }
}

and do not forget add MyApplication class in manifest:

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

Upvotes: 12

Manish
Manish

Reputation: 67

This works for me:

C:\Users\example>keytool -exportcert -alias androiddebugkey -keystore 
"C:\Users\example\.android" | "C:\openssl\bin\openssl.exe" sha1 -binary 
| "C:\openssl\bin\oenssl.exe" base64

Upvotes: 0

Keshav Gera
Keshav Gera

Reputation: 11244

Downloads and Unzip

You can download openssl for windows 32 and 64 bit from the respective links below:

https://code.google.com/archive/p/openssl-for-windows/downloads

OpenSSL for 64 Bits OpenSSL for 32 Bits

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | **"C:\Users\keshav.gera\openssl-0.9.8k_X64\bin**\openssl.exe" sha1 -binary | **"C:\Users\keshav.gera\openssl-0.9.8k_X64\bin**\openssl.exe" base64

Important change our path Here as well as install open ssl in your system

It's Working No Doubt

C:\Users\keshav.gera>keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\Users\keshav.gera\openssl-0.9.8k_X64\bin\openssl.exe" sha1 -binary | "C:\Users\keshav.gera\openssl-0.9.8k_X64\bin\openssl.exe" base64

Enter keystore password: android

**ZrRtxw36xWNYL+h3aJdcCeQQxi0=**

=============================================================

using Manually through Coding

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


private void PrintHashKey() {

        try {
            PackageInfo info = getPackageManager().getPackageInfo("**com.keshav.patanjalidemo  Your Package Name Here**", 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) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

    }

Upvotes: 2

sandhu
sandhu

Reputation: 305

Steps to create Hash Key. 
1: Download openssl from Openssl for Windows . I downloaded the Win64 version 
2:Unzip and copy all the files in the bin folder including openssl.exe(All file of bin folder) 
3:Goto to the folder where you installed JDK for me it’s C:\Program Files\Java\jdk1.8.0_05\bin 
4:Paste all the files you copied from Openssl’s bin folder to the Jdk folder. 

then go C:\Program Files\Java\jdk1.8.0_05\bin and press shift key and right click and open cmd

C:\Program Files\Java\jdk1.8.0_05\bin>//cmd path 

that is for Sha1 past this
keytool -exportcert -alias androiddebugkey -keystore "C:\User\ABC\.android.keystore" | openssl sha1 -binary | openssl base64
//and ABC is system name put own system name

Upvotes: 6

Oladipo Olasemo
Oladipo Olasemo

Reputation: 2020

for windows users download open ssl from google's code repository https://code.google.com/p/openssl-for-windows/downloads/list

After the download, extract the contents to a folder preferably in your c: drive.

Then update your PATH environment variable so you can use the .exe from any location in your command line.

[windows 8] To update your PATH environment variable, click my computer->properties->Advanced System Settings.

Click the Advanced Tab and click the 'Environment Variable' button at the bottom of the dialog then select the Path entry from the 'System Variables' Section by clicking edit.

Paste the path to the bin folder of the extracted openssl download and click ok.

You will need to close and open and command prompt you may have previously launched so that you can load the updated path settings.

Now run this command:

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

You should see the developer key.

Upvotes: 0

DjP
DjP

Reputation: 4577

go to bin folder path in cmd and then run following command

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

you will get your key hash

Upvotes: 0

Vibhor Kashyap
Vibhor Kashyap

Reputation: 83

First navigate to your Java/jre/bin folder in cmd cd c:\Program Files (x86)\Java\jre7\bin

Then use : [change debug.keystore path to the correct location on your system] install openssl (for windows 32 or 64 as per your needs at c:\openssl )

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\vibhor\.android\debug.keystore" | "c:\openssl\bin\openssl.exe" sha1 -binary | "c:\openssl\bin\openssl.exe" base64

So the whole command goes like this : [prompts to enter keystore password on execution ]

c:\Program Files (x86)\Java\jre7\bin>keytool -exportcert -alias androiddebugkey
-keystore "C:\Users\vibhor\.android\debug.keystore" | "c:\openssl\bin\openssl.ex
e" sha1 -binary | "c:\openssl\bin\openssl.exe" base64
Enter keystore password:

Upvotes: 6

Azahar
Azahar

Reputation: 385

use this worked for me. please change your Path

C:\Program Files\Java\jre7\bin keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Ace.android\debug.keystore" | "C:\openssl\bin

\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64

Upvotes: 1

Nirav Shah
Nirav Shah

Reputation: 2084

It is not guaranteed that generating hashkey with this single openssl method will work. If it does not work for me. But thanks for giving me a direction to solve my issue.

Guaranteed Solution : You need to break the whole command in separate commands and have to write output of every execution in file.

You can take the help from the following link :

http://www.helloandroid.com/tutorials/using-facebook-sdk-android-development-part-1

Enjoy :)

Upvotes: 0

GAURAV KUMAR GUPTA
GAURAV KUMAR GUPTA

Reputation: 786

Please follow these step, I hope your key working properly:

  1. Step 1 You will need OpenSSL. You can download the binary from openssl-for-windows project on Google Code.

  2. 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.

  3. 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.

Upvotes: 37

Nguyễn Kim
Nguyễn Kim

Reputation: 21

I used this code:

This is worked for me successfully.

"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

Upvotes: 2

Kaloyan Drenski
Kaloyan Drenski

Reputation: 1066

Use the entire path, like this:

exportcert -alias androiddebugkey -keystore ~/.android
/debug.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\op
enssl.exe" base64

It worked for me.

Upvotes: 27

Haze
Haze

Reputation: 53

For those looking for a more recent location to install a windows binary version of openssl (32bit and 64bit) you can find it here:

http://slproweb.com/products/Win32OpenSSL.html

An up to date list of websites that offer binary distributions is here

http://www.openssl.org/related/binaries.html

Upvotes: 0

Siddiq Abu Bakkar
Siddiq Abu Bakkar

Reputation: 1949

This is worked for me successfully.

"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

Be careful with below path :

  • "C:\Program Files\Java\jdk1.6.0_26\bin\keytool.exe"
  • "D:\keystore\SocialListing" or it can be like this "C:\Users\Shaon.android\debug.keystore"
  • "C:\cygwin\bin\openssl.exe" or can be like this C:\Users\openssl\bin\openssl.exe

If command successfully work then you will see this command :

Enter keystore password : typeyourpassword

Encryptedhashkey**

Upvotes: 11

Related Questions