Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android資訊 >> Android簽名相關知識整理

Android簽名相關知識整理

編輯:Android資訊

不止一次有用到Android簽名相關的知識,每次都幾乎從零開始在Google上搜索找,不想在繼續這樣了,找了個時間好好整理了一下自己用到的一些碎片知識,於是乎放到這裡,一是備忘,二是幫助別人。

從APK文件中獲取簽名信息

使用方法

keytool -list -printcert -jarfile your_apk_file

輸出信息

  • 簽名Owner,Issuer等信息
  • 簽名的fingerprints,如md5及sha1等值
  • 簽名有效期等信息

示例效果

16:29 $ keytool -list -printcert -jarfile akoi_1.2.apk
Signer #1:

Signature:

Owner: CN=Andrew Wallace, OU=droidyue.com, O=droidyue.com, L=Beijing, ST=Beijing, C=86
Issuer: CN=Andrew Wallace, OU=droidyue.com, O=droidyue.com, L=Beijing, ST=Beijing, C=86
Serial number: 11a8a4a3
Valid from: Tue Feb 10 18:07:43 CST 2015 until: Sun Jun 13 18:07:43 CST 3013
Certificate fingerprints:
   MD5:  46:C5:BE:EF:B5:C9:00:E1:FA:42:50:50:57:54:CA:15
   SHA1: C1:14:5D:0A:C2:BF:F6:06:43:20:AE:2C:07:12:97:58:C2:1B:39:D1
   SHA256: 0E:88:7D:C2:4C:D6:84:A7:58:D4:24:1E:9D:38:F9:05:98:1E:B2:A2:D7:CB:0F:81:74:60:5B:38:89:FF:21:1C
   Signature algorithm name: SHA256withRSA
   Version: 3

從簽名文件中獲取簽名信息

使用方法

keytool -list -v -keystore your_kestore_file

注意,上述命令執行後,會提示輸入密碼,其實輸入錯誤也沒有關系,不影響結果。

輸出信息

  • 簽名Owner,Issuer等信息
  • 簽名的fingerprints,如md5及sha1等值
  • 簽名有效期等信息

示例效果

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: droidyue.com
Creation date: Feb 10, 2015
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Andrew Wallace, OU=droidyue.com, O=droidyue.com, L=Beijing, ST=Beijing, C=86
Issuer: CN=Andrew Wallace, OU=droidyue.com, O=droidyue.com, L=Beijing, ST=Beijing, C=86
Serial number: 11a8a4a3
Valid from: Tue Feb 10 18:07:43 CST 2015 until: Sun Jun 13 18:07:43 CST 3013
Certificate fingerprints:
   MD5:  46:C5:BE:EF:B5:C9:00:E1:FA:42:50:50:57:54:CA:15
   SHA1: C1:14:5D:0A:C2:BF:F6:06:43:20:AE:2C:07:12:97:58:C2:1B:39:D1
   SHA256: 0E:88:7D:C2:4C:D6:84:A7:58:D4:24:1E:9D:38:F9:05:98:1E:B2:A2:D7:CB:0F:81:74:60:5B:38:89:FF:21:1C
   Signature algorithm name: SHA256withRSA
   Version: 3

重新簽名APK

在沒有源碼情況下,我們就能對apk進行更換簽名。

腳本

  • signapk.sh
  • 備用地址

使用方法

bash signapk.sh your_apk_file your_keystore_file keystore_pass keystore_alias

示例效果

16:57 $ bash signapk.sh weixin6313android740.apk ~/Documents/baidu_disk/百度雲同步盤/droidapp/mykiki 123456 droidyue.com
param1 weixin6313android740.apk
param2 /Users/androidyue/Documents/droidapp/mykiki
param3 123456
param4 droidyue.com
deleting: META-INF/MANIFEST.MF
deleting: META-INF/DROIDYUE.SF
deleting: META-INF/DROIDYUE.RSA
   adding: META-INF/MANIFEST.MF
   adding: META-INF/DROIDYUE.SF
   adding: META-INF/DROIDYUE.RSA
......
Verification succesful

生成的文件會放在當前目錄,其文件名相對輸入文件,增加了signed_前綴,比如對weixin6313android740.apk進行上述操作得到的輸出文件是signed_weixin6313android740.apk

Gradle build生成簽名APK

想要在執行gradle build時生成指定簽名的apk,需要在build.gradle中如下修改

android {

    signingConfigs {
        release {
            storeFile file("myrelease.keystore")
            storePassword "********"
            keyAlias "******"
            keyPassword "******"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved