233

我在这里阅读 Facebook 开发人员的开发指南

它说我必须使用 keytool 来导出我的应用程序的签名,例如:

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

我不知道如何找到 keytool 来运行它。我尝试打开 Windows 命令提示符并粘贴上述命令,但没有成功。

4

22 回答 22

226

我自己找到了一个解决方案,如下引用。它工作正常。

"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
于 2011-08-26T07:15:39.957 回答
134

Simply enter these into Windows command prompt.

cd C:\Program Files\Java\jdk1.7.0_09\bin

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\userName\.android\debug.keystore" -list -v

The base password is android

You will be presented with the MD5, SHA1, and SHA256 keys; Choose the one you need.

于 2013-02-06T18:41:19.843 回答
80

To get android key hash code follow these steps (for facebook apps)

  1. Download the openssl for windows here
  2. now unzip to c drive
  3. open cmd prompt
  4. type cd C:\Program Files\Java\jdk1.6.0_26\bin
  5. then type only keytool -export -alias myAlias -keystore C:\Users\<your user name>\.android\myKeyStore | C:\openssl-0.9.8k_WIN32\bin\openssl sha1 -binary | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e
  6. Done

To get Certificate fingerprint(MD5) code follow these steps

  1. go to - C:\Program Files\Java\jdk1.6.0_26\bin
  2. inside the bin folder run the jarsigner.exe file
  3. open cmd prompt
  4. type cd C:\Program Files\Java\jdk1.6.0_26\bin
  5. then again type on cmd keytool -list -keystore "C:/Documents and Settings/<your user name>/.android/debug.keystore"
  6. it will ask for Keystore password now. The default is "android" type and enter
  7. Done.
于 2012-07-15T15:51:04.393 回答
26

keytool 是 JDK 的一部分。

尝试添加%{JAVA_HOME}\到 exec 语句或c:\{path to jdk}\bin.

于 2011-03-30T15:22:11.710 回答
16

I found this on another post, which did not get many upvotes, but it was super helpful for me. So will add it here.

Android Studio will bring a keytool with it.

C:\Program Files\Android\Android Studio\jre\bin

You can see his post below by Richar Heap, with a helpful reference. I did see this before but forgot about it. https://stackoverflow.com/a/51524526/4446406

于 2020-04-25T13:08:56.550 回答
13

KeyTool 是 JDK 的一部分。假设您使用默认设置安装了 JDK,您会找到它,在$JAVA_HOME/bin

于 2011-03-30T15:26:43.650 回答
9

Robby Pond's answer can be generalized to use JAVA_HOME environment variable and to also compensate for any blanks that might occur in the path (like Program Files):

"%JAVA_HOME%\bin\keytool" -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
于 2017-09-17T15:55:58.143 回答
5

keytool 是 jdk 的一部分,它应该是 $JAVA_HOME/bin/keytool

于 2011-03-30T15:22:33.463 回答
5

keytool 位于 JDK bin 目录 ($JAVA_HOME/bin) 中。JAVA_HOME 是您的 JDK 安装目录。要使用该命令行,您还应该将 $JAVA_HOME/bin 包含到您的 PATH 环境变量中。

于 2011-03-30T15:22:55.807 回答
4

Keytool 是 Java SDK 的一部分。您应该能够在您的 Java SDK 目录中找到它,例如 C:\Program Files\Java\jdk1.6.0_14\bin

于 2011-03-30T15:23:15.997 回答
4

On cmd window (need to run as Administrator),

cd %JAVA_HOME% 

only works if you have set up your system environment variable JAVA_HOME . To set up your system variable for your path, you can do this

setx %JAVA_HOME% C:\Java\jdk1.8.0_121\

Then, you can type

cd c:\Java\jdk1.8.0_121\bin

or

cd %JAVA_HOME%\bin

Then, execute any commands provided by JAVA jdk's, such as

keytool -genkey -v -keystore myapp.keystore -alias myapp

You just have to answer the questions (equivalent to typing the values on cmd line) after hitting enter! The key would be generated

于 2017-01-23T21:33:15.257 回答
3

Android:在 android 中运行 keytool 命令的位置

如果您的类路径变量中设置了 JRE,则可以在您的 dos 命令提示符下运行 Keytool 命令。

例如,如果你想获取Android SDK调试证书的MD5指纹,

只需运行以下命令...

C:\Documents and Settings\user\.android>  keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

where C:\Documents and Settings\user\.android> is the path which contains the debug.keystore that has to be certified.

For detailed information, please visit http://code.google.com/android/add-ons/google-apis/mapkey.html#getdebugfingerprint

于 2011-12-07T07:49:33.860 回答
3

Depending on your version of Eclipse ( I am using Kepler). Go to Windows> Preferences>Android> Build.

You'll find the location path of your debug keystore as well as the SHA1 fingerprint (which you can just copy and use)

于 2014-04-21T18:10:37.930 回答
3

If you installed visual studio with Xamarin/mobile development support, you'll have a java install here C:\Program Files\Android\jdk\microsoft_dist_openjdk_{version}\bin\, as was my case.

于 2019-12-20T17:27:44.320 回答
2

KEYTOOL is in JAVAC SDK .So you must find it in inside the directory that contaijns javac

于 2015-11-26T13:58:12.420 回答
2

In addition to Gareth's

answer above, the below worked for me

Simply enter these into Windows command prompt.

Make sure the terminal is run as adminstrator

  1. cd C:\Program Files\Android\Android Studio\jre\bin

  2. keytool -list -v -keystore "C:\Users\admin.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Read more

N:B: This should be done after the first build, as the keys are only generated after first build

于 2021-03-19T13:51:25.487 回答
1

keytool随JDK一起提供。如果您使用的是 cygwin,那么这可能已经在您的路径上。否则,您可能会在 JDK 的 bin 文件夹中四处寻找。

无论如何,您可能都需要使用 cygwin 才能使 shell 管道 ( |) 工作。

于 2011-03-30T15:22:29.790 回答
1

Few observations while I was getting the same problem (Windows). 1. Shell pipe is important. 2. If you are using OpenSSL or Cygwin, definitely you have to install it. 3. keytool comes with JDK so either you have to point to it in the command or you have cd to the JDK/bin folder (where the exe resides) 4. The debug keystore is typically located at ~/.android/debug.keystore 5. password is "android" whether you -keypass it or type it when prompted. 6. For the alias name, you can open (DO NOT SAVE, just open and close) the keystore file with any editor and read it. 7. MOST IMPORTANT - There is a difference is specifying the keystore path within quotes and without. I got it working by using the keystore path within the double quotes. As remix090378 said and as per the instruction, this command indeed worked - cd C:\Program Files\Java\jdk1.7.0_09\bin

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\userName.android\debug.keystore" -list -v

于 2015-02-03T17:22:56.863 回答
0

In my case, I had already generated an APK file using the command ionic cordova build android --prod and I needed to get the SHA-1 fingerprint for the already existing APK file. Here's how I got it by running the following command in the App directory:

keytool -list -printcert -jarfile app-debug.apk

So, I basically ran the above command in the following app location:

C:\myApp\platforms\android\app\build\outputs\apk\debug>keytool -list -printcert -jarfile app-debug.apk

This gave me the SHA1 fingerprint as: 7B:6B:AD:...

Hope this helps someone!

于 2020-03-02T08:04:09.423 回答
0

Alternatively you can do the following :

  • copy the bat file below in any folder already present in your PATH environment variable
  • then simply use keytool command in any Windows shell

Actual location of keytool is defined in the bat file. In case the location is wrong the bat file will scan your system to detect potential locations in ProgramFiles (sub)folders.

Also find keytool2.bat, a convinient shortcut for "keytool -v -list -keystore", which is widely used to quickly check the content of a jks file.

keytool.bat :


:: 
:: 
:: "keytool alias" script by Céphas
:: easy method : add the known keytool.exe folder to your personal PATH variable (run : C:\Windows\System32\rundll32.exe sysdm.cpl,EditEnvironmentVariables)
:: else, add the folder containing this bat script to your personal path or put this script in any folder already defined in your path
::
:: also see keytool2.bat that automatically adds the following parameters in the keytool command line : -v -list -keystore, for quick display of jks content
:: 
:: 
@echo off
set THIS_SCRIPT=%~f0
rem  setlocal enableDelayedExpansion : necessary for paths containing special chars
setlocal enableDelayedExpansion

rem  set PATH to keytool.exe ; path must include the final \
rem  ^ is escape char for paths containing & \ < > ^ | 
set PATH_TO=C:\Program Files\Java\jre1.8.0_45\bin\
set PROG_NAME=keytool.exe

rem full_path, with "", to work with paths containing special chars
set FULL_KT_PATH="!PATH_TO!!PROG_NAME!"

rem checks if keytool.exe exists
(dir %FULL_KT_PATH%>nul 2>nul && set KT_FOUND=yes) || set KT_FOUND=no

if %KT_FOUND%==yes (
    rem keytool found => launching it with all supplied parameters
    rem 
    rem
    %FULL_KT_PATH% %*
    rem
    rem
) else (
    rem keytool not found, trying to find it in %ProgramFiles%

    echo.
    echo Keytool not found in expected location, scan in progess ...
    echo.

    cd "%ProgramFiles(x86)%" 2>nul && dir /B /S keytool.exe 2>nul

    cd "%ProgramFiles%" 2>nul && dir /B /S keytool.exe 2>nul

    echo.
    echo *********
    echo Path to program keytool.exe not properly defined, or keytool/java missing on this system
    echo If any location has been found during above scan, fix variable "PATH_TO" in %THIS_SCRIPT% accordingly
    echo *********
    echo.
    pause
    
)    

keytool2.bat :


:: 
:: 
:: "keytool2 alias" script by Céphas
:: easy method : add the known keytool.exe folder to your personal PATH variable (run : C:\Windows\System32\rundll32.exe sysdm.cpl,EditEnvironmentVariables)
:: else, add the folder containing this bat script to your personal path or put this script in any folder already defined in your path
::
:: keytool2 automatically adds the following parameters in the keytool command line : -v -list -keystore
:: thus, to quickly display the full content of a jks file, usage is simply : keytool2 \path\to\your\keystore.jks [-alias your_alias]
:: 
:: 
@echo off
set THIS_SCRIPT=%~f0
rem  setlocal enableDelayedExpansion : necessary for paths containing special chars
setlocal enableDelayedExpansion

rem  set PATH to keytool.exe ; path must include the final \
rem  ^ is escape char for paths containing & \ < > ^ | 
set PATH_TO=C:\Program Files\Java\jre1.8.0_45\bin\
set PROG_NAME=keytool.exe


rem full_path, with "", to work with paths containing special chars
set FULL_KT_PATH="!PATH_TO!!PROG_NAME!"

rem checks if keytool.exe exists
(dir %FULL_KT_PATH%>nul 2>nul && set KT_FOUND=yes) || set KT_FOUND=no

if %KT_FOUND%==yes (
    rem keytool found => launching it with all supplied parameters
    rem 
    rem
    %FULL_KT_PATH% -v -list -keystore %*
    rem
    rem
) else (
    rem keytool not found, trying to find it in %ProgramFiles%

    echo.
    echo Keytool not found in expected location, scan in progess ...
    echo.

    cd "%ProgramFiles(x86)%" 2>nul && dir /B /S keytool.exe 2>nul

    cd "%ProgramFiles%" 2>nul && dir /B /S keytool.exe 2>nul

    echo.
    echo *********
    echo Path to program keytool.exe not properly defined, or keytool/java missing on this system
    echo If any location has been found during above scan, fix variable "PATH_TO" in %THIS_SCRIPT% accordingly
    echo *********
    echo.
    pause
    
)    

于 2020-10-02T12:15:33.883 回答
0

On Windows

If your using Jetbrain's Toolbox, to manage Android Studio update, the path is something like

C:\Users\{USERNAME}\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\202.7486908\jre\bin 

After an update I have to manually update/set this path as JAVA_HOME (the jre folder)

于 2021-08-19T09:16:52.347 回答
-1

Given that you have installed Java and preferably a JDK in your system ( answering for Windows because you mentioned it in your question) you should have the keytool utility on your installation's bin folder.

If that's the case, what you can do next is add that bin folder to the PATH environment variable of your Windows installation.

The next time you will open a Windows shell and you'll type keytool you will be able to run the actual utility.

于 2020-03-18T09:56:05.840 回答