1.使用platform密鑰對apk進(jìn)行簽名
1.1.進(jìn)入<Android_Source_Path>/build/target/product/security,找到【platform.pk8】和【platform.x509.pem】系統(tǒng)密鑰。
1.2.進(jìn)入<Android_Source_Path>/build/tools/signapk找到SignApk.java,運(yùn)行javac編譯成SignApk.class
1.3.執(zhí)行命令java com.android.signapk.SignApk platform.x509.pem platform.pk8 input.apk output.apk
至此,完成。
2. 對1的補(bǔ)充:
<Android_Source_Path>/build/target/product/security下有多對密鑰,詳細(xì)如下:
The following commands were used to generate the test key pairs:
development/tools/make_key testkey '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key platform '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key shared '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key media '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
The following standard test keys are currently included:
testkey -- a generic key for packages that do not otherwise specify a key.
platform -- a test key for packages that are part of the core platform.
shared -- a test key for things that are shared in the home/contacts process.
media -- a test key for packages that are part of the media/download system.
These test keys are used strictly in development, and should never be assumed
to convey any sort of validity. When $BUILD_SECURE=true, the code should not
honor these keys in any context.
signing using the openssl commandline (for boot/system images)
--------------------------------------------------------------
1. convert pk8 format key to pem format
% openssl pkcs8 -inform DER -nocrypt -in testkey.pk8 -out testkey.pem
2. create a signature using the pem format key
% openssl dgst -binary -sha1 -sign testkey.pem FILE > FILE.sig
extracting public keys for embedding
------------------------------------
it's a Java tool
but it generates C code
take a look at commands/recovery/Android.mk
you'll see it running $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
3.對3的補(bǔ)充:
在運(yùn)行第三步的命令前,請?jiān)谀惝?dāng)前的工作目錄下新建如下結(jié)構(gòu)的文件夾:com.android.signapk,然后將第二步編譯生成的SignApk放入該目錄下?;蛘咭部梢詫ignApk.java的package聲明刪除后再運(yùn)行javac編譯。
命令java com.android.signapk.SignApk platform.x509.pem platform.pk8 input.apk output.apk
不單可以對apk文件進(jìn)行重簽名,也可以對所有的zip文件進(jìn)行重簽名,包括ROM文件。