1、使用jarsigner和keystore加签
在github上下载keytool-importkeypair,将系统签名文件(platform.pk8, platform.x509.pem)转换成keystore文件(platform.keystore)
./keytool-importkeypair -k platform.keystore -p platform -pk8 platform.pk8 -cert platform.x509.pem -alias platform
用jdk自带的jarsigner通过keystore对apk进行加签
/home/sops/jdk1.8.0_281/bin/jarsigner -verbose -storepass platform -keystore platform.keystore -signedjar signed.apk old.apk platform
2、使用安卓自带的signapk.jar进行apk加签(android/out/host/linux-x86/framework/signapk.jar)(lib64目录位置:android/out/host/linux-x86/lib64)
java -Xmx3g -Djava.library.path=./lib64 -jar signapk.jar platform.x509.pem platform.pk8 ${OLD_APK_NAME} ${APK_PKG_NAME}
3、openssl生成keystore,然后用jarsigner加签
openssl pkcs8 -inform DER -nocrypt -in testkey.pk8 -out testkey.pem
openssl pkcs12 -export -in testkey.x509.pem -out testkey.p12 -inkey testkey.pem -password pass:testkey -name testkey
/home/sops/jdk1.8.0_281/bin/keytool -importkeystore -deststorepass testkey -destkeystore testkey.keystore -srckeystore ./testkey.p12 -srcstoretype PKCS12 -srcstorepass testkey
/home/sops/jdk1.8.0_281/bin/jarsigner -verbose -storepass testkey -keystore testkey.keystore -signedjar signed.apk rawpatch.apk testkey
4、验证签名结果:/home/sops/jdk1.8.0_281/bin/keytool -printcert -jarfile 签名后的apk
注意:重新加签需要删除原有的加签文件:
查看加签文件:unzip -v rawpatch.apk
删除加签文件:zip rawpatch.apk -d zip a.apk -d META-INF/*