Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> Android學習之使用platform密鑰來給apk文件簽名的命令

Android學習之使用platform密鑰來給apk文件簽名的命令

編輯:初級開發

1.使用platform密鑰對apk進行簽名
1.1.進入<android_Source_Path>\build\target\product\security,找到【platform.pk8】和【platform.x509.pem】系統密鑰。
1.2.進入<android_Source_Path>\build\tools\signapk找到SignApk.java,運行 Javac編譯成SignApk.class
1.3.執行命令Java com.android.signapk.SignApk platform.x509.pem platform.pk8 input.apk output.apk

至此,完成。


2. 對1的補充:
<android_Source_Path>\build\target\product\security下有多對密鑰,詳細如下:

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/[email protected]'
  development/tools/make_key platform '/C=US/ST=California/L=Mountain VIEw/O=Android/OU=Android/CN=Android/[email protected]'
  development/tools/make_key shared   '/C=US/ST=California/L=Mountain VIEw/O=Android/OU=Android/CN=Android/[email protected]'
  development/tools/make_key media    '/C=US/ST=California/L=Mountain VIEw/O=Android/OU=Android/CN=Android/[email protected]'

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的補充:
在運行第三步的命令前,請在你當前的工作目錄下新建如下結構的文件夾:com.android.signapk,然後將第二步編譯生成的 SignApk放入該目錄下。或者也可以將SignApk.java的package聲明刪除後再運行Javac編譯。

命令Java com.android.signapk.SignApk platform.x509.pem platform.pk8 input.apk output.apk

不單可以對apk文件進行重簽名,也可以對所有的zip文件進行重簽名,包括ROM文件。
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved