Android Digital Signature Parsing (iii)

Source: Internet
Author: User

the KeyStore , X509, key pair, Debug.keystore, which appeared in the data at the time when the relevant knowledge points of the Android digital signature were just started .
turn, after a period of understanding, finally understand some.

One, Make_key script generates key pair
the tool Make_key (development/tools/directory) that comes with the Android source code can be used to generate an RSA key pair.

./make_key test '/c=cn/st=sh/l=sh/o=test/ou=test/cn=test '

running the above command will generate the key pair Test.pk8 and TEST.X509.PEM. in this command, /C means "country Code",/st means "state or province ",/L means" city or
Locality ",/O means" Organization ",/ou means" organizational Unit ",/CN table display "Name".

the key code in the Make_key script is as follows:

</pre></div></blockquote><pre name= "code" class= "HTML" > (OpenSSL genrsa-f4 2048 | Tee ${one} & Gt  ${two}) &openssl Req-new-x509-sha1-key ${two}-out $1.x509.pem-days   10000-subj "$" &if ["${password}" == "" ]; Then  echo "Creating ${1}.pk8 with no password"  OpenSSL pkcs8-in ${one}-topk8-outform der-out $1.pk8-nocryptel Se  echo "Creating ${1}.pk8 with Password [${password}]"  echo $password | OpenSSL pkcs8-in ${one}-topk8-outform Der-out $1.pk8     -passout stdin

In
fact, the main use of OpenSSL to achieve, OpenSSL is a powerful command, to understand OpenSSL, you can refer to Baidu encyclopedia Http://baike.baidu.com/view/300712.htm?fr=aladdin

second, Keytool generate key
Android Digital Signature Resolution (i) describes how to generate a key using Keytool,

keytool-genkey-alias test.keystore-keyalg rsa-validity 10000-keystore test.keystore

Keytool is the tool that comes with the JDK, some third-party application developers, because there is no Android source environment, so will use Keytool to generate the key.


third, the key pair generated by Make_key is converted to a key in KeyStore

1. Convert the private key in the PKCS8 format to the PKCS12 format:
OpenSSL pkcs8-in test.pk8-inform der-outform pem-out test.priv.pem-nocrypt

2. Generate the key file in PKCS12 format:
OpenSSL pkcs12-export-in test.x509.pem-inkey test.priv.pem-out test.pk12-name testkey

3. Generate KeyStore:
keytool-importkeystore-deststorepass android-destkeypass android-destkeystore test.keystore-srckeystore shared.pk12
srcstoretype pkcs12-srcstorepass android-alias testkey

This
generates a KeyStore file named Test.keystore, which you can use to sign the APK.

iv.converting keys in KeyStore to key pairs
1. convert keystore file to PKCs12 format
keytool-importkeystore-srckeystore test.keystore-destkeystore test.p12-srcstoretype jks-deststoretype PKC S12

2. Dump pkcs12 file
OpenSSL pkcs12-in test.p12-nodes-out Test.rsa.pem

3, open Test.rsa.pem as text, copy" BEGIN CERTIFICATE " " END CERTIFICATE "to a file
test.x509.pem, public key
4 . Copy the content between " BEGIN RSA private Key" "END RSA private Key" to a file Test.rsa.pem, then run the following command
     
OpenSSL pkcs8-topk8-outform der-in test. Rsa.pem-inform pem-out test. pk8-nocry PT

so the TEST.X509.PEM and test.pk8 are generated.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.