简体   繁体   English

使用 keytool 获取证书的 MD5 签名

[英]Using keytool to get the MD5 signature of a certificate

I need to get a Google map key for my application and, for this, I need the MD5 signature of my certificate.我需要为我的应用程序获取一个 Google 地图密钥,为此,我需要我的证书的 MD5 签名。 As seen on the Internet, I use "keytool" to get it :正如在互联网上看到的,我使用“keytool”来获取它:

keytool -list -alias mykey -keystore mykeystore

The problem is that the answer is a SHA1 signature instead of an MD5 signature.问题是答案是 SHA1 签名而不是 MD5 签名。

I use JDK 1.7.我使用 JDK 1.7。

What am I doing wrong?我究竟做错了什么?

Thanks in advance for the time you will spend trying to help me.预先感谢您花时间帮助我。

There is another Post about this same thing How can I get the MD5 fingerprint from Java's keytool, not only SHA-1?还有另一篇关于同一件事的帖子如何从 Java 的密钥工具中获取 MD5 指纹,而不仅仅是 SHA-1?

I guess JDK 1.7 defaults to SHA1.我猜 JDK 1.7 默认为 SHA1。 To fix this the following has worked:为了解决这个问题,以下方法有效:

C:\Program Files\Java\jdk1.7.0\bin>keytool -v -list -alias
androiddebugkey -keystore debug.keystore -storepass android -keypass android

I tried this, and it worked for me.我试过这个,它对我有用。 It gives you MD%, SHA1, SHA256 and Signature Algorithm Name.它为您提供 MD%、SHA1、SHA256 和签名算法名称。 In that order.以该顺序。

keytool -exportcert -alias alias -keypass keypass -keystore ./test.keystore -storepass 123456 | md5sum

Hello in the year 2021.你好,2021 年。

The keytool of JDK 8 and newer does not print MD5 anymore, even if you try the standard suggestion to add the "-v" option to the "keygen -list" command. JDK 8 和更新版本的 keytool 不再打印 MD5,即使您尝试将“-v”选项添加到“keygen -list”命令的标准建议也是如此。

I guess MD5 is no more considered secure enough and has been removed .我猜 MD5 不再被认为足够安全并且已被删除

At the same time there are still places like Amazon "Security Profile Management" for LWA etc. requiring you to submit the MD5 signature of your certificate.同时还有像亚马逊的“Security Profile Management for LWA”等地方要求你提交证书的MD5签名。

Here is a command which will deliver it (use the password "android" for the Android Studio keystore):这是一个将传递它的命令(使用 Android Studio 密钥库的密码“android”):

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | \
openssl dgst -md5 

And if you want to have colon character inbetween, then add the following "sed" command:如果您想在中间添加冒号字符,请添加以下“sed”命令:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | \
openssl dgst -md5 | \
sed 's/[a-fA-F0-9][a-fA-F0-9]/&:/g; s/:$//'

The above command works on Linux, macOS and even Windows (in git bash):上面的命令适用于 Linux、macOS 甚至 Windows(在 git bash 中):

MinGW 截图

Have you tried the keytool command as:您是否尝试过使用 keytool 命令:

$ keytool -list -keystore ~/.android/debug.keystore

More on getting Map API Key is Here: http://code.google.com/android/maps-api-signup.html有关获取 Map API 密钥的更多信息,请访问: http : //code.google.com/android/maps-api-signup.html

Update:更新:

As you are using JDK 1.7, there is a new command line argument to its keytool, namely -keyalg.当您使用 JDK 1.7 时,它的 keytool 有一个新的命令行参数,即 -keyalg。

I know you can specify -keyalg RSA, so maybe -keyalg MD5 will give you the right key.我知道你可以指定 -keyalg RSA,所以也许 -keyalg MD5 会给你正确的密钥。

通过回到 java 1.6 解决。

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

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