1.首先需要一个已签名的apk文件(demo.apk)
可使用keytool -list -printcert -jarfile demo.apk查看签名信息

2.一个签名秘钥(lgh.keystore)
3.把两个文件放到同一个目录下
4.把已签名的apk文件后缀改成.zip,然后编辑这个文件,找到META-INF文件夹,并删除
5.把.zip后缀改回.apk
6.使用命令 jarsigner -verify demo.apk查看是否签名

7.使用命令
jarsigner -verbose -keystore lgh.keystore -storepass xxx -signedjar demo-signed.apk -digestalg SHA1 -sigalg MD5withRSA demo.apk [xxxkeystore别名]
命令行参数说明:
-jarsigner:是Java的签名工具
-verbose:参数表示显示出签名详细信息
-keystore:表示使用当前目录中的lgh.keystore签名证书文件
-storepass xxx :表示Keystore密码:“xxx”
-signedjar demo-signed.apk:表示签名后生成的APK名称
-digestalg SHA1 -sigalg MD5withRSA:表示签名的算法是使用MD5withRSA
(注意MD5withRSA算法已经被弃用,取而代之的则是SHA256withRSA)
demo.apk :表示需要签名的apk
[xxxkeystore别名] :表示lgh.keystore的别名,注意是别名不是文件名称


8.使用命令 jarsigner -verify demo.apk查看是否签名

提示说签名不生效,使用的算法被禁用了,再回看apk的签名信息中,发现使用的算法是SHA256withRSA,所以需要把MD5withRSA改成SHA256withRSA,重新对apk进行签名,完成后查看是否签名

完成~~~
网友评论