简体   繁体   English

如何在 Android 上获取 OAuth 2.0 的签名证书指纹 (SHA1)?

[英]How to obtain Signing certificate fingerprint (SHA1) for OAuth 2.0 on Android?

I'm trying to register my android app following the steps in https://developers.google.com/console/help/#installed_applications which leads me to follow http://developer.android.com/tools/publishing/app-signing.html .我正在尝试按照https://developers.google.com/console/help/#installed_applications中的步骤注册我的 android 应用程序,这导致我关注http://developer.android.com/tools/publishing/app-签名.html

However, I'm not sure how to get the signing certificate fingerprint (SHA1).但是,我不确定如何获取签名证书指纹(SHA1)。

I first used the Eclipse ADT plugin to export and create the keystore/key.我首先使用 Eclipse ADT 插件来导出和创建密钥库/密钥。 Then, I tried doing keytool -list keystore mykeystore.keystore and it gives me a MD5 Certificate fingerprint.然后,我尝试执行keytool -list keystore mykeystore.keystore并且它给了我一个 MD5 证书指纹。 Do I need to redo the signing (meaning I can't use the eclipse export wizard)?我是否需要重做签名(意味着我不能使用 eclipse 导出向导)?

Can I use a debug certificate first?我可以先使用调试证书吗?

Start an export process to create an apk for your app and use your production key.启动导出过程,为您的应用创建 apk 并使用您的生产密钥。 The very last page displays both your SHA1 and MD5 certificate fingerprints最后一页显示您的 SHA1 和 MD5 证书指纹在此处输入图片说明

I know this question has been answered but this is how I found my signature for the default keystore.我知道这个问题已经得到解答,但这就是我找到默认密钥库签名的方式。 In Eclipse, if you go to Windows -> Preferences -> Android -> Build在 Eclipse 中,如果你去 Windows -> Preferences -> Android -> Build

在此处输入图片说明

I think this will work perfectly.我认为这将完美地工作。 I used the same:我用了同样的:

For Android Studio:对于安卓工作室:

  1. Click on Build > Generate Signed APK .单击Build > Generate Signed APK
  2. You will get a message box, just click OK.您将收到一个消息框,只需单击“确定”即可。
  3. Now there will be another window just copy Key Store Path .现在将出现另一个窗口,只需复制Key Store Path 即可
  4. Now open a command prompt and go to C:\\Program Files\\Java\\jdk1.6.0_39\\bin> (or any installed jdk version).现在打开命令提示符并转到C:\\Program Files\\Java\\jdk1.6.0_39\\bin> (或任何已安装的 jdk 版本)。
  5. Type keytool -list -v -keystore and then paste your Key Store Path (Eg. C:\\Program Files\\Java\\jdk1.6.0_39\\bin>keytool -list -v -keystore "E:\\My Projects \\Android\\android studio\\signed apks\\Hello World\\HelloWorld.jks").键入keytool -list -v -keystore然后粘贴您的密钥存储路径(例如 C:\\Program Files\\Java\\jdk1.6.0_39\\bin>keytool -list -v -keystore "E:\\My Projects\\Android\\android工作室\\签名的 apks\\Hello World\\HelloWorld.jks”)。
  6. Now it will Ask Key Store Password , provide yours and press Enter to get your SHA1 and MD5 Certificate keys.现在它将询问Key Store Password ,提供您的密码并按Enter以获取您的 SHA1 和 MD5 证书密钥。

If you are using Mac or even Linux, just copy and paste this onto the Terminal application and you will get the SHA1 key immediately.如果您使用的是 Mac 甚至 Linux,只需将其复制并粘贴到终端应用程序上,您将立即获得 SHA1 密钥。 No need to change anything.不需要改变任何东西。

 keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

Example output:示例输出:

Alias name: androiddebugkey
Creation date: 17 Feb 12
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4f3dfc69
Valid from: Fri Feb 17 15:06:17 SGT 2012 until: Sun Feb 09 15:06:17 SGT 2042
Certificate fingerprints:
     MD5:  11:10:11:11:11:11:11:11:11:11:11:11:11:11:11:11
     SHA1: 11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:01:11
     Signature algorithm name: SHA1withRSA
     Version: 3

在命令行中使用它

c:\Program Files\Java\jdk1.6.25\bin>keytool -list -v -keystore c:\you_key_here.key

Open terminal (in Unix , in MAC ), ( cmd in Windows ) and cd to this (your java) path:打开终端(在Unix 中,在MAC 中),(在Windows 中为cmd )并cd到此(您的 java)路径:

C:\Program Files\Java\jdk1.6.0_43\bin>

Run this command:运行此命令:

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

Just change the path to debug.keystore and you will get both MD5 and SHA-1 fingerprints.只需更改debug.keystore的路径,您将获得 MD5 和 SHA-1 指纹。

keytool -list -v -keystore "keyStoreName"

从应用程序密钥库所在的目录运行此命令。

In Android Studio, follow these steps:在 Android Studio 中,请按照下列步骤操作:

  1. Click Gradle properties menu at right side of your android studio IDE.单击 android studio IDE 右侧的 Gradle 属性菜单。
  2. Expand Task tree.展开任务树。
  3. Click on signingReport You can see your SHA1 at the bottom console点击signingReport你可以在底部控制台看到你的SHA1

在此处输入图片说明

See if you want to use Google Map at that time you need MD5 fingerprint for generating api kay for using google map in your android application.看看你当时是否想使用Google Map ,你需要MD5指纹来生成api kay以便在你的 android 应用程序中使用谷歌地图。

Keytool command generated MD5 fingerprint if you use JDK 1.6 and it generates SHA1 fingerprint if you use JDK 1.7 . keytool命令生成MD5指纹,如果您使用JDK 1.6和它产生SHA1如果使用指纹JDK 1.7

So the thing is that if you want to sign your application for publishing then read this .所以问题是,如果您想签署您的应用程序以进行发布,请阅读 .

And if you want to use google-map readthis .如果您想使用google-map请阅读.

If you are using IntelliJ (12+?), go to menu Build/Generate signed Api如果您使用的是 IntelliJ(12+?),请转到菜单Build/Generate signed Api

After filling a popup, get the data in the field "key store path" (eg C:\\Users\\user\\Documents\\store\\store)填充弹出后,获取“key store path”字段中的数据(例如C:\\Users\\user\\Documents\\store\\store)

And run in a command line:并在命令行中运行:

>keytool -list -v -keystore "C:\Users\user\Documents\store\store"

....
         MD5: 11:C5:09:73:50:A4:E5:71:A2:26:13:E0:7B:CD:DD:6B
    -->  SHA1: 07:0B:0E:E8:F7:22:59:72:6A:1C:68:05:05:CF:2E:6F:59:43:48:99
         SHA256: E6:CE:DA:37:C1:18:43:C1:A3:F0:9E:8F:1A:C2:69:AF:E6:41:F7:C0:18:
1D:1D:55:5D:F0:52:6C:EE:77:84:A7
...

Good luck祝你好运

If any one using the Android studio...如果有人使用 Android 工作室...

click: Build > Generate Signed in APK Create a new key: this will generated ".jks" files单击:Build > Generate Signed in APK 创建一个新密钥:这将生成“.jks”文件

Use following command to read the data(SHA1 and other info):使用以下命令读取数据(SHA1 和其他信息):

$ keytool -list -v -keystore filename.jks $ keytool -list -v -keystore 文件名.jks

For those using OpenSSL you can retrieve the SHA1 fingerprint this way:对于使用 OpenSSL 的用户,您可以通过以下方式检索 SHA1 指纹:

OpenSSL> dgst -sha1 my-release-key.keystore

Which would result in the following output:这将导致以下输出:

在此处输入图片说明

Here is my easy solution for this:这是我的简单解决方案:

Click on Gradle button, you can find at the right side top.单击Gradle按钮,您可以在右侧顶部找到。 you will see all the gradle files.你会看到所有的 gradle 文件。 Now go to android, and double click on signingReport.现在转到android,然后双击signingReport。 Once the gradle build finishes, you see the SHA key. gradle 构建完成后,您会看到 SHA 密钥。 Check the below images for step by step guide.检查下面的图像以获取分步指南。

Once you click on Gradle check the below images.单击 Gradle 后,请检查以下图像。 Hope this helps someone.希望这可以帮助某人。

STEP 1:第1步:

图片第一步

STEP 2:第2步:

图片步骤二

试试这个:Windows----preferences----Android--build---sh1 code copy from here

If you are using Android Studio.如果您使用的是 Android Studio。 You can get fastly the SHA1 certificate fingerprint (debug,release... all Build Types !!) through Gradle Tasks :您可以通过Gradle Tasks快速获取SHA1 证书指纹(调试、发布...所有构建类型!!):

signingReport签约报告

SHA1 is shown in Messages Logs SHA1 显示在消息日志中

Android Plugin (configured in the gradle app) creates a debug mode for default. Android 插件(在 gradle 应用程序中配置)默认创建调试模式。

com.android.application com.android.application

File route to keystore:到密钥库的文件路径:

HOME/.android/debug.keystore主页/.android/debug.keystore

I recommend attach debug.keystore to build.gradle.我建议debug.keystore附加到 build.gradle。 To do this put a file debug.keystore to a app folder and then Add SigningConfigs in gradle app:为此,将文件 debug.keystore 放入应用程序文件夹,然后在 gradle 应用程序中添加 SigningConfigs:

apply plugin: 'com.android.application'

    android {
        ................
        signingConfigs {
            debug {
                storeFile file("../app/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }
            release {
                storeFile file("../app/debug.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }
        }    
        ........
    }

Extra: If you want creates for release, put a file release.keystore to a app folder.额外:如果您想为发布创建,请将文件 release.keystore 放入应用程序文件夹。 (This example uses the same debug.keystore) (此示例使用相同的 debug.keystore)

If you are using Android Studio.如果您使用的是 Android Studio。 You don't need to generate a SHA1 fingerprint using cmd prompt.您不需要使用 cmd 提示符生成 SHA1 指纹。 You just need to create a project with default Maps Activity of Android Studio.In the project you can get the fingerprint in google_maps_api.xml under Values folder.您只需要使用Android Studio 的默认Maps Activity 创建一个项目。在该项目中,您可以在Values 文件夹下的google_maps_api.xml 中获取指纹。 Hope this will help you.希望这会帮助你。 :) :)

在此处输入图片说明

I was so confusing first time, but I propose you final working solution for Windows:我第一次很困惑,但我建议你为 Windows 提供最终的工作解决方案

1) Open cmd and go to your Java/jdk/bin directory (just press cd .. to go one folder back and cd NAME_FOLDER to go one folder forward), in my case, final folder: C:\\Program Files\\Java\\jdk1.8.0_73\\bin> 1) 打开 cmd 并转到您的 Java/jdk/bin 目录(只需按cd ..返回一个文件夹,然后按cd .. cd NAME_FOLDER向前移动一个文件夹),在我的情况下,最终文件夹: C:\\Program Files\\Java\\jdk1.8.0_73\\bin> 在此处输入图片说明

2) Now type this command keytool -list -v -keystore C:\\Users\\YOUR_WINDOWS_USER\\.android\\debug.keystore -alias androiddebugkey -storepass android -keypass android 2) 现在输入这个命令keytool -list -v -keystore C:\\Users\\YOUR_WINDOWS_USER\\.android\\debug.keystore -alias androiddebugkey -storepass android -keypass android

As result you have to get something like this:结果你必须得到这样的东西: 在此处输入图片说明

I think this will work perfectly.我认为这将完美地工作。 I used the same:我用了同样的:

For Android Studio:对于安卓工作室:

Click on Build > Generate Signed APK.单击构建 > 生成签名的 APK。 You will get a message box, just click OK.您将收到一个消息框,只需单击“确定”即可。

Now there will be another window just copy Key Store Path.现在将有另一个窗口,只需复制密钥存储路径。

Now open a command prompt and go to C:\\Program Files\\Java\\jdk1.6.0_39\\bin> (or any installed jdk version).现在打开命令提示符并转到 C:\\Program Files\\Java\\jdk1.6.0_39\\bin>(或任何已安装的 jdk 版本)。

Type keytool -list -v -keystore and then paste your Key Store Path (Eg. C:\\Program Files\\Java\\jdk1.6.0_39\\bin>keytool -list -v -keystore "E:\\My Projects \\Android\\android studio\\signed apks\\Hello World\\HelloWorld.jks").键入 keytool -list -v -keystore 然后粘贴您的密钥存储路径(例如 C:\\Program Files\\Java\\jdk1.6.0_39\\bin>keytool -list -v -keystore "E:\\My Projects\\Android\\android工作室\\签名的 apks\\Hello World\\HelloWorld.jks”)。

Now it will Ask Key Store Password, provide yours and press Enter to get your SHA1 and MD5 Certificate keys.现在它将询问密钥存储密码,提供您的密码并按 Enter 以获取您的 SHA1 和 MD5 证书密钥。

Now add this SHA1 key to the google developers console in credentials tab and also change the build variants in android studio to release mode.现在将此 SHA1 密钥添加到凭据选项卡中的 google 开发人员控制台,并将 android studio 中的构建变体更改为发布模式。

Please Click on Gradle from Right side of Menu Then Click on :app Then Click android folder Then SigningReport file name is exist there Double click on that.请单击菜单右侧的 Gradle 然后单击 :app 然后单击 android 文件夹然后 SigningReport 文件名存在那里双击它。 It Will start executing and in a while it will show you SHA-1 Code Just copy the code.它将开始执行,一段时间后它会向您显示 SHA-1 代码 只需复制代码即可。 And paste it where you need it并将其粘贴到您需要的地方

在图像中突出显示的签名报告

For those on mac looking for keytool.对于那些在 mac 上寻找 keytool 的人。 follow these steps:按着这些次序:

Firstly make sure to install Java JDK http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html首先确保安装 Java JDK http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html

Then type this into command prompt:然后在命令提示符中输入:

/usr/libexec/java_home -v 1.7

it will spit out something like:它会吐出类似的东西:

/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home

keytool is located in the same directory as javac . keytool 与javac位于同一目录中。 ie: IE:

/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin

From bin directory you can use the keytool.从 bin 目录中,您可以使用 keytool。

If you are on Mac/Linux, then you can get SHA1 fingerprint by writing following line in the terminal:如果您使用的是 Mac/Linux,那么您可以通过在终端中写入以下行来获取 SHA1 指纹:

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

There are 2 things possible after this在这之后有两件事可能

  1. It will ask you for the password它会要求你输入密码

    Just type只需输入

android安卓

and press enter, you can find the SHA1 key in the output shown below.然后按回车,你可以在下面显示的输出中找到 SHA1 密钥。

  1. It will ask you to download a suitable program (and some list will be given)它会要求你下载一个合适的程序(并且会给出一些列表)

    Just type following in terminal只需在终端中输入以下内容

sudo apt install openjdk-8-jre-headless sudo apt 安装 openjdk-8-jre-headless

and then again run following in terminal: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android然后再次在终端中运行以下命令: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

This time, you will be led to step 1, where you need to just enter the password as这一次,您将进入第 1 步,您只需输入密码即可

android安卓

and you will get your SHA1 fingerprint below in the output.您将在输出中获得下面的 SHA1 指纹。

If you want to obtain fingerprint-sha1 key from signing keystore.jks file Run the following command from terminal:如果要从签名 keystore.jks 文件中获取指纹 sha1 密钥,请从终端运行以下命令:

keytool -list -v -keystore <.../path/keystore.jks>

Example例子

keytool -list -v -keystore /Users/Home/Projects/Keystore/myApp_keystore.jks
Enter keystore password: 

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name:myApp_alias
Owner: CN=xxx, OU=xxx Dev, O=ZZZ, L=Dhaka, ST=Dhaka, C=BD
..........


Certificate fingerprints:
MD5:  12:10:11:12:11:11:11:11:11:11:33:11:11:11:11:11
SHA1: 11:44:11:11:55:11:17:11:11:66:11:11:88:11:11:77:11:11:01:11
.....................

Using portecle :使用portecle

  • File > Open Keystore file文件 > 打开密钥库文件
  • Enter Keystore password输入密钥库密码
  • Right click on alias name > Certificate details > SHA-1 Fingerprint右键单击别名 > 证书详细信息 > SHA-1 指纹

Easiest way to Get SHA-1 For Release and Debug mode android studio gradle.为发布和调试模式 android studio gradle 获取 SHA-1 的最简单方法。 Check this 检查这个

I wanted to post a notice to those that are having the same issue as me.我想向那些与我有同样问题的人发布通知。 I went through the steps to generate my debug SHA-1 and my release SHA-1.我完成了生成调试 SHA-1 和发布 SHA-1 的步骤。 I was attempting to connect Google Sign-In API with my app.我试图将 Google Sign-In API 与我的应用程序连接。

I ran into the issue that the debug .apk would work fine, it would connect and authenticate with Google Sign-In.我遇到了调试 .apk 可以正常工作的问题,它可以连接并使用 Google Sign-In 进行身份验证。 My release .apk would also work, when installed manually to the phone.当手动安装到手机时,我的发行版 .apk 也可以使用。 When I posted my release .apk to the Google play store, my google Sign-in would not authenticate and I would get an issue!当我将发布的 .apk 发布到 Google Play 商店时,我的 google 登录无法通过身份验证,我会遇到问题!

For the longest time I couldn't figure it out, but I found that my app was being signed by google, ie, the message on the top of the Developer console was showing: Google Play App Signing is enabled for this app.很长一段时间我都想不通,但我发现我的应用被谷歌签名,即开发者控制台顶部的消息显示: Google Play App Signing is enabled for this app。

I went to my Release Management tab, then scrolled down to App Signing, and found the SHA-1 there.我转到我的发布管理选项卡,然后向下滚动到应用签名,并在那里找到了 SHA-1。 After adding this to my code and on "firebase console" which I was using as the backend for Google Sign-in, everything seemed to work.将此添加到我的代码和我用作 Google 登录后端的“firebase 控制台”上后,一切似乎都正常了。 It looks like my release keystore was getting replaced with the google signed certificate... I'm not really sure if this is what was happening, but it resolved my issue and allowed my Google Play Store release apk to correctly authenticate with the google sign in!看起来我的发布密钥库被谷歌签名证书取代了......我不确定这是不是发生了什么,但它解决了我的问题并允许我的 Google Play 商店发布 apk 正确地使用谷歌签名进行身份验证在!

Step by step solution:分步解决:

  1. Open your command prompt or Terminal for Mac打开 Mac 的命令提示符或终端
  2. Change directory to directory of the keytool file location.将目录更改为 keytool 文件位置的目录。 Change directory by using command cd <directory path> .使用命令cd <directory path>更改目录。 (Note: if any directory name has space then add \\ between the two words. Example cd /Applications/Android\\ Studio.app//Contents/jre/jdk/Contents/Home/bin/ ) (注意:如果任何目录名称有空格,则在两个单词之间添加\\ 。示例cd /Applications/Android\\ Studio.app//Contents/jre/jdk/Contents/Home/bin/

    • To find the location of your keytool, you go to android studio..open your project.要找到 keytool 的位置,请转到 android studio..打开您的项目。 And go to然后去

    • File>project Structure>SDK location..and find JDK location. File>project Structure>SDK location..并找到JDK位置。

  3. Run the keytool by this command: keytool -list -v –keystore <your jks file path> (Note: if any directory name has space then add \\ between the two words. example keytool -list -v -keystore /Users/username/Desktop/tasmiah\\ mobile/v3/jordanos.jks )通过这个命令运行keytool: keytool -list -v –keystore <your jks file path> (注意:如果任何目录名称有空格,则在两个单词之间添加\\。例如keytool -list -v -keystore /Users/username/Desktop/tasmiah\\ mobile/v3/jordanos.jks )

  4. Command prompt you to key in the password.. so key in your password.. then you get the result命令提示你输入密码..所以输入你的密码..然后你得到结果

Here is tool for lazy coders:这是懒惰程序员的工具:

1 add dependency: 1 添加依赖:

compile 'com.vk:androidsdk:1.6.9'

2 add following lines somewhere in your activity/application: 2 在您的活动/应用程序中的某处添加以下几行:

String[] fingerprints = VKUtil.getCertificateFingerprint(this, getPackageName()); 
Log.d("SHA1", fingerprints[0]);

3 Open logcat and catch message. 3 打开 logcat 并捕获消息。

4 Profit! 4 利润!

  1. Open your command prompt打开你的命令提示符
  2. Navigate working directory to 1.8.0/bin将工作目录导航到 1.8.0/bin
  3. paste keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\\.android\\debug.keystore粘贴keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\\.android\\debug.keystore
  4. Press enter if it ask you a password如果它询问您密码,请按 Enter

In latest version of Android Studio best way to get the SHA-1 key is form terminal.在最新版本的 Android Studio 中,获取 SHA-1 密钥的最佳方式是表单终端。 Android Studio 北极狐 , ,

  1. open terminal in Android studio在 Android Studio 中打开终端
  2. Copy the command( keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android)复制命令(keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android)
  3. Paster it on terminal and press the enter key将其粘贴到终端上并按回车键

if you still facing the problem, you need to follow this first: enter link description here如果您仍然遇到问题,则需要先按照此操作:在此处输入链接描述

then go to pubspec.yaml and do pub upgrade , then type the .然后转到 pubspec.yaml 并执行pub upgrade ,然后键入 . /gradlew SigningReport in terminal. /gradlew SigningReport在终端中。 it'll definitely works!!它肯定会奏效!! .. ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM