我可以使用与附带证书不同的证书重新签署 .apk 吗?

发布于 2024-09-10 09:01:36 字数 213 浏览 2 评论 0原文

如果我有 apk,我可以删除当前签名以及如何使用不同的 .keystore 文件重新签名并仍然安装应用程序吗?

更新:我设法让它与 Jorgesys 的解决方案一起使用,之前我搞砸的地方是我解压了 .apk,然后在删除 META-INF 文件夹后重新压缩它,并将文件扩展名改回为.apk。我应该做的只是用 winzip 打开它并删除 winzip 中的文件夹。

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

柏林苍穹下 2024-09-17 09:01:36

试试这个

1) 将 .apk 的扩展名更改为 .zip

2) 打开并删除文件夹 META-INF

3) 将扩展名更改为.apk

4) 将 jarsigner 和 zipalign 与新密钥库结合使用。

希望有帮助

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.

hope it helps

飘然心甜 2024-09-17 09:01:36

如果您正在寻找快速简单的解决方案,可以使用 Google 的 apksigner 命令行 工具,该工具在版本 24.0.3 及更高版本中可用。

apksigner 签名 --ks release.jks application.apk

您可以在 Android 开发者网站上找到有关 apksigner 工具的更多信息。

https://developer.android.com/studio/command-line/apksigner.html

或者,您也可以使用开源 apk-resigner 脚本

开源 apk-resigner 脚本 https://github.com/onbiron/apk-resigner

您所要做的就是下载脚本并输入:

 ./signapk.sh application.apk 密钥库密钥传递别名

If you are looking for a quick simple solution, you can use Google's apksigner command line tool which is available in revision 24.0.3 and higher.

apksigner sign --ks release.jks application.apk

You can find more information about apksigner tool, at the developer Android site.

https://developer.android.com/studio/command-line/apksigner.html

Or, alternatively, you may use an open-source apk-resigner script

Open Source apk-resigner script 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
雪若未夕 2024-09-17 09:01:36

请注意,如果您使用 v2 签名架构(如果您使用 build- AS 中的工具 24.0.3+)您不能只从 APK 中删除 META-INF 文件夹,因为 v2 将其签名数据添加到 zip 元块中。

然而,Google 在 build-tools 24.03 (Android 7) 中引入的新 apksigner 是能够放弃 APK。您只需重复签名命令即可使用新的密钥库/证书进行签名(旧的密钥库/证书将被删除)。

apksigner sign --ks keystore.jks signed_app.apk

无耻插件:如果你想要一个更简单的工具,可以签署多个apk并具有更好的日志输出,请使用: https://github.com/patrickfav/uber-apk-signer(在后台使用 Google 的 apksigner.jar)

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.

Google's new apksigner introduced 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).

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)

紫南 2024-09-17 09:01:36
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
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
鼻尖触碰 2024-09-17 09:01:36

签名发布:$1.apk -> $1_release.apk”
GeneralMills 和 GoogleApps#2012
第 1 步:删除任何先前的签名
将 .apk 的扩展名更改为 .zip
打开并删除文件夹 META-INF
将扩展名更改为 .apk
或者
命令:
• zip [原始apk]
例子:
• zip "$1".apk -d

第 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

步骤 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

步骤 4:清理
命令:
• rm 4 [未对齐的apk]
例子:
• rm "$1"_unaligned.apk

其他命令可能有帮助:

  1. 使用 keytool 生成新密钥
    keytool -genkey -alias -keystore

  2. 列出密钥
    keytool -list -keystore

用于为 Facebook 功能生成 keyhash 的命令


• keytool -exportcert -alias alias_name -keystore [keystorefile] | keytool -exportcert -alias alias_name -keystore [keystorefile] | keytool -exportcert -alias openssl sha1 - 二进制 | openssl base64

示例:
• C:\Program Files\Java\jdk1.6.0_43\bin>keytool -exportcert -alias release -keyst
orerelease.keystore|打开l sha1-二进制| openssl base64

注意:
为了签署我们的 APK,我们将 JDK 从 1.7 降级到 1.6.0_43 更新。

原因:
从 JDK 7 开始,默认签名算法已更改,要求您在签署 APK 时指定签名和摘要算法(-sigalg 和 -digestalg)。

命令:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [密钥库文件]
[原始apk] 别名

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

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

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

Step 4: Cleaning up
Command:
• rm 4 [unalignedapk]
Example:
• rm "$1"_unaligned.apk

Additional Commands might help:

  1. To generate new key with keytool
    keytool -genkey -alias -keystore

  2. To list keys
    keytool -list -keystore

Command to generate a keyhash for the Facebook features

Command:
• 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

Note:
To sign our apks we have downgraded JDK from 1.7 to 1.6.0_43 update.

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.

Command:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [keystorefile]
[originalapk] alias_name

奢望 2024-09-17 09:01:36

上述所有解决方案都有效。请注意为什么重新压缩后它不起作用:

.apk 中的某些文件需要保持存储状态(压缩率为 0%)。这是因为Android将使用内存映射(mmap)来读取内容而不解压到内存中。此类文件是 .ogg 和一些图标。

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.

夏夜暖风 2024-09-17 09:01:36

假设您的密钥存储在 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

来确定密钥的别名。然后运行:

zip -d your_app.apk "META-INF/*"
jarsigner -verbose -keystore keys.keystore \
   -sigalg MD5withRSA -digestalg SHA1 -sigfile CERT \
   your_app.apk your_key_alias

使用名为 your_key_alias 的密钥重新签名 your_app.apk

从 JDK 8 开始,额外的 -sigfile CERT 选项似乎是必需的。

Assuming your keys are stored in keys.keystore, you can run:

$ 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.

The extra -sigfile CERT option seems to be necessary as of JDK 8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文