如何最简单地找到apk文件的签名?请注意,我并不是在询问代码,我只是想从我的电脑中找到它。类似于这个 975yYkKAQF+KST7g3ASHvHkYopq= 的签名。
$ $ANDROID_SDK/build-tools/$BUILD_TOOLS_VERSION/apksigner verify --print-certs -v $APK_FILE
例子:
$ /Users/hborders/android/build-tools/29.0.2/apksigner verify --print-certs -v ~/Desktop/my-apk.apk
Verifies
Verified using v1 scheme (JAR signing): true
Verified using v2 scheme (APK Signature Scheme v2): true
Verified using v3 scheme (APK Signature Scheme v3): false
Number of signers: 1
Signer #1 certificate DN: CN=Bob Smith, OU=Acme, O=Acme, L=San Francisco, ST=California, C=US
Signer #1 certificate SHA-256 digest: f1f2f3f3f21f26a67s76a6a76a76a76a76a67c78c8c78c709c90c90c09932451
Signer #1 certificate SHA-1 digest: 839103847abdefcbade123713957358920
Signer #1 certificate MD5 digest: 182831983712923f2e2e2f2a2c2fbc25
Signer #1 key algorithm: RSA
Signer #1 key size (bits): 1024
Signer #1 public key SHA-256 digest: 8acaca8cabcaabdadc8cc99cc695ace47aec4c747c746c476cae4657c47c4765
Signer #1 public key SHA-1 digest: b11bca4123bea24befbe5b8be9768ef078
apksigner
是 Android SDK 中 build-tools
目录的一部分。它是工具print-apk-signature
使用的。
keytool -printcert -jarfile app-release.apk
您还可以获取密钥库的签名,请查看此文章:如何检查APK和密钥库文件的SHA1或签名
Signature[] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)
{
Trace.i("MyApp", "Signature hashcode : " + sig.hashCode());
}
http://developer.android.com/reference/android/content/pm/PackageManager.html
这可能有所帮助
首先,解压APK并提取文件/META-INF/ANDROID_.RSA(该文件也可能是CERT.RSA,但只应有一个.RSA文件)。
然后发出此命令:
keytool -printcert -file ANDROID_.RSA 您将获得类似于此的证书指纹:
MD5: B3:4F:BE:07:AA:78:24:DC:CA:92:36:FF:AE:8C:17:DB
SHA1: 16:59:E7:E3:0C:AA:7A:0D:F2:0D:05:20:12:A8:85:0B:32:C5:4F:68
Signature algorithm name: SHA1withRSA
然后再次使用keytool打印出您签名密钥库的所有别名:
keytool -list -keystore my-signing-key.keystore 您将得到一个别名列表和它们的证书指纹:
android_key, 2010年1月23日, PrivateKeyEntry, 证书指纹(MD5): B3:4F:BE:07:AA:78:24:DC:CA:92:36:FF:AE:8C:17:DB 太好了!我们现在可以确定apk已经使用这个密钥库签名,并且使用别名'android_key'。
Keytool是Java的一部分,因此请确保您的PATH中有Java安装目录。
apksigner
来获取签名。ebra@him:~/Android/Sdk/build-tools/30.0.3$ ./apksigner verify --print-certs -v ~/application.apk
Verifies
Verified using v1 scheme (JAR signing): false
Verified using v2 scheme (APK Signature Scheme v2): true
Verified using v3 scheme (APK Signature Scheme v3): true
Verified using v4 scheme (APK Signature Scheme v4): false
Verified for SourceStamp: false
Number of signers: 1
Signer #1 certificate DN: CN=Supreeth Herle
Signer #1 certificate SHA-256 digest: 87f10d5ab8a769bff49200039bbd5d17a0f9d0b9bcccabc36527ec3c98d978dd
Signer #1 certificate SHA-1 digest: e46872f28b350b7e1f140de535c2a835804f0be3
Signer #1 certificate MD5 digest: fabb11667489da8f214ed30d8efd0979
Signer #1 key algorithm: RSA
Signer #1 key size (bits): 2048
Signer #1 public key SHA-256 digest: 530468d2918764b0244a46ea406bfeb1742f4da73b6d86eefb4005c37fc04a3b
Signer #1 public key SHA-1 digest: 884c2bf64530118dde84250ed8a03e2c2c2bb3aa
然后,您可以使用内置的Linux工具将相应的签名转换为所需的格式(即base64):
ebra@him:~/Android/Sdk/build-tools/30.0.3$ ./apksigner verify --print-certs -v ~/application.apk | grep 'certificate SHA-1' | cut -d ':' -f 2 | xxd -r -p | base64
5Ghy8os1C34fFA3lNcKo1YBPC+M=