如何获取APK签名?
有没有办法检索用于签署 APK 的密钥的签名?我使用密钥库中的密钥签署了我的 APK。我如何以编程方式检索它?
Is there a way to retrieve the signature of the key used to sign an APK? I signed my APK with my key from my keystore. How can I retrieve it programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 PackageManager 类访问 APK 的签名
http://developer.android.com/reference/android/content/pm /PackageManager.html
我用它来与我的调试密钥的哈希码进行比较,作为识别 APK 是调试 APK 还是发布 APK 的方法。
You can access the APK's signing signature like this using the PackageManager class
http://developer.android.com/reference/android/content/pm/PackageManager.html
I've used this to compare with the hashcode for my debug key, as a way to identify whether the APK is a debug APK or a release APK.
包管理器将为您提供任何已安装包的签名证书。然后您可以打印出签名密钥的详细信息,例如
The package manager will give you the signing certificate for any installed package. You can then print out the details of the signing key, e.g.
我的情况是我有一个预安装的 apk 使用了错误的 key-store 。所以直接安装会因为签名不一致而失败。我需要先检查签名以确保可以顺利安装。
这是我的解决方案。
正如此代码所述,您可以从已安装的apk中获取签名。
详细信息:
其次:获取releaseApk hashCode进行比较。就我而言,我从服务器下载了这个 apk,并将其放入 sd_card 中。
最后比较hashCode。
我已经尝试过上面的代码,它工作得很好。如果 hashCode 不同,您应该卸载旧的 apk,或者如果它是系统应用程序并且设备已 root,您可以使用runtime删除它,然后安装新的签名apk。
My situation is that I have a pre-installed apk which use a wrong key-store . So directly install will give a fail because of inconsistent signature.I need to check the signature first to make sure it can be install smoothly.
Here is my solution.
As this code says, you can get the signature from an installed apk.
details:
Secondly: get the releaseApk hashCode to compare. In my case, I downloaded this apk from my server, and put it in the sd_card.
Finally,compare the hashCode.
I have tried the code above, it works just fine. If the hashCode is different, you should just uninstall the old apk or if it's a system app and the device is rooted, you can just use runtime to remove it,and then install the new signature apk.