Android 我可以使用与附带的证书不同的证书重新签署 .apk 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3267216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I re-sign an .apk with a different certificate than what it came with?
提问by Anton
If I have an apk can I remove the current signing and some how re-sign it with a different .keystore file and still have the application install?
如果我有一个 apk,我可以删除当前的签名以及如何使用不同的 .keystore 文件重新签名并仍然安装应用程序吗?
Update: I managed to get it to work with Jorgesys' solution and where I messed up before was that I unzipped the .apk then rezipped it after removing the META-INF folder and changed the file extension back into .apk. What I should have done is simply opened it with winzip and delete the folder inside of winzip.
更新:我设法让它与 Jorgesys 的解决方案一起使用,我之前搞砸的地方是我解压缩了 .apk,然后在删除 META-INF 文件夹后重新压缩它并将文件扩展名改回 .apk。我应该做的只是用winzip打开它并删除winzip里面的文件夹。
回答by Jorgesys
try this
尝试这个
1) Change the extension of your .apk to .zip
2) Open and remove the folder META-INF
3) Change the extension to .apk
4) Use the jarsigner and zipalign with your new keystore.
1) 将 .apk 的扩展名更改为 .zip
2) 打开并删除文件夹 META-INF
3) 将扩展名更改为 .apk
4) 使用 jarsigner 和 zipalign 与您的新密钥库。
hope it helps
希望能帮助到你
回答by Aksel Fatih
If you are looking for a quick simple solution, you can use Google's apksigner
command linetool which is available in revision 24.0.3 and higher.
如果您正在寻找快速简单的解决方案,您可以使用Google 的apksigner
命令行工具,该工具在 24.0.3 及更高版本中可用。
apksigner sign --ks release.jks application.apk
apksigner sign --ks release.jks application.apk
You can find more information about apksigner tool, at the developer Android site.
您可以在开发人员 Android 站点上找到有关 apksigner 工具的更多信息。
https://developer.android.com/studio/command-line/apksigner.html
https://developer.android.com/studio/command-line/apksigner.html
Or, alternatively, you may use an open-source apk-resigner script
或者,您也可以使用开源 apk-resigner 脚本
Open Source apk-resigner script https://github.com/onbiron/apk-resigner
开源 apk-resigner 脚本https://github.com/onbiron/apk-resigner
All you have to do is, download the script and just type:
您所要做的就是下载脚本并输入:
./signapk.sh application.apk keystore key-pass alias
./signapk.sh application.apk keystore key-pass alias
回答by Patrick Favre
Note if you use v2 signing schema(which you will automatically if you use build-tools 24.0.3+ in AS) you cannot just remove the META-INF folder from the APK since v2 adds its signing data to a zip meta block.
请注意,如果您使用v2 签名模式(如果您在 AS 中使用 build-tools 24.0.3+,您将自动使用),您不能仅从 APK 中删除 META-INF 文件夹,因为 v2 将其签名数据添加到 zip 元块。
Google's new apksignerintroduced in build-tools 24.03 (Android 7) is however able to resign APKs. You can just repeat the signing command to sign with a new keystore/cert (the old ones will be removed).
谷歌在 build-tools 24.03 (Android 7) 中引入的新 apksigner 能够重新签名APK。您只需重复签名命令即可使用新的密钥库/证书进行签名(旧的将被删除)。
apksigner sign --ks keystore.jks signed_app.apk
Shameless plug: if you want a easier tool that can sign multiple apks and has better log output use: https://github.com/patrickfav/uber-apk-signer(uses Google's apksigner.jar in the background)
无耻的插件:如果你想要一个更简单的工具,可以签署多个apk并且有更好的日志输出使用:https: //github.com/patrickfav/uber-apk-signer(在后台使用谷歌的apksigner.jar)
回答by kreker
zip -d my_application.apk META-INF/\*
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name
zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
回答by Harsha.Vaswani
Signing for release: $1.apk -> $1_release.apk" GeneralMills&GoogleApps#2012 Step 1: Removing any previous signing Change the extension of your .apk to .zip Open and delete the folder META-INF Change the extension to .apk Or Command: ? zip [originalapk] Example: ? zip "$1".apk -d
签名发布:$1.apk -> $1_release.apk" GeneralMills&GoogleApps#2012 第 1 步:删除任何以前的签名 将 .apk 的扩展名更改为 .zip 打开并删除文件夹 META-INF 将扩展名更改为 .apk 或命令: ? zip [originalapk] 示例:? zip "$1".apk -d
Step 2: Signing with release.keystore.. Command: ? jarsigner –verbose –keystore [keystorefile] –signedjar [unalignedapk] [originalapk] alias_name Example: ? C:\Program Files\Java\jdk1.6.0_43\bin> jarsigner -verbose -keystore release.keystore -signedjar "$1"_unaligned.apk "$1".apk release
第 2 步:使用 release.keystore 签名。命令:?jarsigner –verbose –keystore [keystorefile] –signedjar [unalignedapk] [originalapk] alias_name 示例:?C:\Program Files\Java\jdk1.6.0_43\bin> jarsigner -verbose -keystore release.keystore -signedjar "$1"_unaligned.apk "$1".apk release
Step 3: Aligning Command: ? zipalign -f 4 [unalignedapk] [releaseapk] Example: ? C:\Users\G535940\Downloads\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\too ls>zipalign -f 4 "$1"_unaligned.apk "$1"_release.apk
第 3 步:对齐命令: ? zipalign -f 4 [unalignedapk] [releaseapk] 示例:? C:\Users\G535940\Downloads\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\too ls>zipalign -f 4 "$1"_unaligned.apk "$1"_release.apk
Step 4: Cleaning up Command: ? rm 4 [unalignedapk] Example: ? rm "$1"_unaligned.apk
第 4 步:清理命令: ? rm 4 [unalignedapk] 示例:? rm "$1"_unaligned.apk
Additional Commands might help:
其他命令可能会有所帮助:
To generate new key with keytool keytool -genkey -alias -keystore
To list keys keytool -list -keystore
使用 keytool keytool -genkey -alias -keystore 生成新密钥
列出密钥 keytool -list -keystore
Command to generate a keyhash for the Facebook features
为 Facebook 功能生成密钥哈希的命令
Command: ? keytool -exportcert -alias alias_name -keystore [keystorefile] | openssl sha1 -binary | openssl base64
命令: ?keytool -exportcert -alias alias_name -keystore [keystorefile] | openssl sha1 -binary | openssl base64
Example: ? C:\Program Files\Java\jdk1.6.0_43\bin>keytool -exportcert -alias release -keyst ore release.keystore |opens l sha1 -binary | openssl base64
例子: ?C:\Program Files\Java\jdk1.6.0_43\bin>keytool -exportcert -alias release -keyst ore release.keystore |opens l sha1 -binary | openssl base64
Note: To sign our apks we have downgraded JDK from 1.7 to 1.6.0_43 update.
注意:为了签署我们的 apk,我们将 JDK 从 1.7 降级到 1.6.0_43 更新。
Reason: As of JDK 7, the default signing algorithim has changed, requiring you to specify the signature and digest algorithims (-sigalg and -digestalg) when you sign an APK.
原因:从 JDK 7 开始,默认签名算法已更改,要求您在签名 APK 时指定签名和摘要算法(-sigalg 和 -digestalg)。
Command: jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [keystorefile] [originalapk] alias_name
命令:jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [keystorefile] [originalapk] alias_name
回答by gilm
All the solutions above work. Just a note why it didn't work for you when you re-zipped:
以上所有解决方案都有效。请注意为什么重新压缩时它对您不起作用:
Some of the files inside the .apk need to remain stored (compression at 0%). This is because Android will use memory mapping (mmap) to read the contents without unpacking into memory. Such files are .ogg and some of the icons.
.apk 中的一些文件需要保持存储状态(压缩率为 0%)。这是因为 Android 将使用内存映射 (mmap) 来读取内容,而无需解压到内存中。这些文件是 .ogg 和一些图标。
回答by Phil Calvin
Assuming your keys are stored in keys.keystore
, you can run:
假设您的密钥存储在 中keys.keystore
,您可以运行:
$ keytool -list -keystore keys.keystore
Your keystore contains 1 entry
your_key_alias, Jan 3, 2013, PrivateKeyEntry,
Certificate fingerprint (SHA1): 8C:C3:6A:DC:7E:B6:12:F1:4C:D5:EE:F1:AE:17:FB:90:89:73:50:53
to determine the alias of your key. Then run:
确定您的密钥的别名。然后运行:
zip -d your_app.apk "META-INF/*"
jarsigner -verbose -keystore keys.keystore \
-sigalg MD5withRSA -digestalg SHA1 -sigfile CERT \
your_app.apk your_key_alias
to re-sign your_app.apk
with the key named your_key_alias
.
your_app.apk
使用名为 的密钥重新签名your_key_alias
。
The extra -sigfile CERT
option seems to be necessary as of JDK 8.
从-sigfile CERT
JDK 8 开始,似乎需要额外的选项。