android - 如何使用 Google App 签名为 Sms Retriever 生成 11 个字符的哈希 key

标签 android command-line google-play keytool

我使用 AppSignatureHelper 类生成了 11 个字符的哈希值。但是在将apk上传到Play商店后,它们的哈希值不再起作用了。我发现 Play 用另一个键替换了键,这就是哈希值也被更改的原因。现在我无法获取 11 字符哈希键。

我不知道如何使用 Google 提供的命令。我从 here 找到了这个命令

keytool -exportcert -alias MyAndroidKey -keystore MyProductionKeys.keystore | xxd -p | tr -d "[:space:]"| echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-"| xxd -r -p | base64 |剪切-c1-11

由于我的应用启用了 Play 应用签名,我将不得不使用此命令,

keytool -exportcert -keystore MyProductionKeys.keystore | xxd -p | tr -d "[:space:]"| echo -n com.example.myapp `cat` | sha256sum | tr -d "[:space:]-"| xxd -r -p | base64 |切-c1-11

我已将 keytool 替换为 JDK 的 bin 文件夹中的路径,但它说 xxd 无法识别,所以我从网站下载了它,现在它说 tr 无法识别,我想它也会说 cut

如果我问这个问题似乎太菜鸟,请原谅我,但是我该如何解决这个问题?

更新:我在 linux 机器上尝试了上面的第二个命令,该命令有效并给了我 11 个字符的哈希值,但 SMS Retriever 仍然无法正常工作。

解决方案:在 Nick Fortescue 的回答的帮助下,我下载了 DER 格式的文件。然后使用以下命令将其转换为 .jks 文件,

keytool -importcert -alias myalias -file deployment_cert.der -keystore certificate.jks -storepass mypassword

然后在 certificate.jks 上执行上面的第一个命令,它成功了!

最佳答案

这是完整的分步指南。

  1. 前往 play console -> open app -> Release management -> App Signing -> Download Certificate 。如下图所示

enter image description here

这将为您提供 deployment_cert.der 文件

  1. deployment_cert.der 文件转换为 .jks 文件

使用下面的命令

keytool -importcert -alias YOUR_ALIAS -file deployment_cert.der -keystore certificate.jks -storepass YOUR_PASSWORD

将 YOUR_ALIAS,YOUR_PASSWORD 替换为您在 keystore 中使用的。如果需要,请使用完整路径代替 deployment_cert.der

输入此命令后会询问

Trust this certificate? [no]: yes

键入 yes 并单击 enter 。它会显示消息

Certificate was added to keystore

这将生成一个新文件 certificate.jks

  1. 现在在终端输入命令

    keytool -exportcert -alias YOUR_ALIAS -keystore certificate.jks | xxd -p | tr -d "[:space:]"| echo -n YOUR_PACKAGE `cat` | sha256sum | tr -d "[:space:]-"| xxd -r -p | base64 |剪切-c1-11

将 YOUR_ALIAS,YOUR_PACKAGE 替换为您在 keystore,project 中使用的。如果需要,请使用完整路径代替 certificate.jks

它会要求输入密码

Enter keystore password: mypassword

输入您的密码,您将获得哈希值。

编辑 MacOS 用户:

如果您使用的是 MacOS,您可以通过安装 coreutils 来安装 sha256sum,如下所示:

brew install coreutils

或者您可以像这样使用 shasum -a 256 而不是 sha256sum:

keytool -exportcert -alias YOUR_ALIAS -keystore certificate.jks | xxd -p | tr -d "[:space:]"| echo -n YOUR_PACKAGE `cat` |沙萨姆-a 256 | tr -d "[:space:]-"| xxd -r -p | base64 |剪切-c1-11

Abhinav Gupta和这个问题的操作 Farhan Farooqui及以上来自 Nick Fortescue 的答案

关于android - 如何使用 Google App 签名为 Sms Retriever 生成 11 个字符的哈希 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51365778/

相关文章:

php - 查找具有特定文本的文件并删除该文本

android - 制作高级版应用程序的最佳方式?

android - 使用修改后的屏幕截图的 Google Play 分阶段发布

android - xml 文件中 View 的“类”属性

android - ScrollView 中的 LinearLayout

android - 不小心改了android :Versioncode to a higher value,现在怎么办?

android - 权限问题 Google Play

android - 可拖动 ListView 的实现

ios - 如何创建目标、向该目标添加资源并使用 xcode 命令行工具构建目标?

c++ - 在 C++ 中使用输出重定向调用外部程序的空文件输出