利用上节<如何生成Android的签名证书> 生成的证书文件给apk签名.
1.生成证书
bash mkkey_for_test.sh media. 得到如下文件:
media.pem // private-key plane
media.pk8 // pk8 private-key
media.x509.pem //证书文件
cat media.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA7diReVxr848dnVpOl2eAo/PDDpu5q7NQaiyggke+ydpIaRXy
HinmjIa7kXB0RxUC+5aMo3gpC6dOcpyA0TWK8oH+wZuYfXyRdLyHwRPPn6QFIFN+
FVLdd+JHrGlXbvmEBn+17qByqW+z6xWEXcBNIumq2NG7D9PBpU4MQBHBQ5KMaL+c
4T54PmA/9IYCKoAKLFxHDs4d77QvsXbHia+AQNWJV59pkVD5fBj2mUQl2t3yZFer
r3Ipy5og3wzrApo3F7/TtRg9bSG5PwFBwqqdpoclLx6D96Pfb9Oo0fRZ826548lz
+4hkcimgdOudOxCxSeH2USWBCcY0lBNA6Oj+eQIBAwKCAQEAnpBg+5Lyol9pE5GJ
ukUAbU0stGfRHSI1nB3AVtp/MTwwRg6haXFEXa8ntkr4L2NXUmRdwlAbXRo0TGhV
4M5coav/K70QU6hg+H2v1g01FRgDauJUDjc+T+wvyEY6SfutWap5ScBMcPUinLkC
6SreF0Zx5eEnX+KBGN6y1WErgmBpx48r3dJUKWm6ZL0qUlSCBP5zSG/sRBFxZsCU
knuU27E4ewnL7x/Mype25C11Irp1yU05qU1viiT15Ps+KX7yWQ4CaCv47fS2ZaQy
QO6n4oNCsxkj0daS+Dxdo9drFRXusG6h+hQ7lmNFg684huS1RDgrZ9v98Z+To0eR
wFrmQwKBgQD+XdbzVBoAjEIdwyMm6/fVS5NibILeYYAWbtDrXlNkD48RUEASwYJ+
kBXKDKCbJJIJzjmBne+602aSm9CKHcO6p4bdlT1JkHBHaGONVmN1HE3uUZuSjglk
EpXb8hvCulAc4ORI7OvDs5fJUL+RHCRCTxPkSd60YzD1zZAU9VVs2wKBgQDvX5Hn
wGj5c/+Kmkcbwwlx2Us3taNdKBnvKIT9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Bphc9H
9ZoCXHtzT8epEkgivZmoILcTJ90pwKGv8HzhdGU+s7x/rSLPG9rXjZ8Q3U6PdJZh
is+/cHqXc+uQFLT3h+djkc1vZRyfcNrJn59AQunEvfZx4UQmw0n9o+4ZhG9VNWtL
LpXujEIBNFGMovHBJZv/HIpIQF1cJRUNcdknELYTrlrlSIDDuvX6CPXYjQelb7Fq
dw==
-----END CERTIFICATE-----
2.apk做签名
其中要用到signapk.jar文件, 这是个java的应用程序, 以下以baidu.apk为例,对其进行签名
java -jar signapk.jar media.x509.pem media.pk8 baidu.apk baidu.apk.sig
3.查看签名信息
jarsigner -certs -verbose -verify baidu.apk.sig
4.查看签名后apk包的文件
jar -tvf baidu.apk.sig, 请自行查看