Android signature mechanism: Generate KeyStore, sign, view signature information

Source: Internet
Author: User
Tags rfc

Android's unique security mechanism, in addition to the authority mechanism, the other is the signature mechanism. Signature mechanism is mainly used in the following two main occasions to play its role: Upgrade app and permission check.

Upgrade your App

When a user upgrades an already installed app, if the program's modifications come from the same source, the upgrade installation is allowed, or a hint that the signature is inconsistent cannot be installed.

Permission check

I have mentioned in the specific use of the Android permission Authority mechanism that the protection level for requesting permission is signature or Signatureorsystem, Checks whether the certificate for the permission requester and the permission declarator is consistent.

As for the principle of signature mechanism and other functions, this is not detailed, this article mainly introduces, the signature file key generation, with key to sign the APK file and the method of viewing the signature.

Generate KeyStore

To create the KeyStore, you need to use Keytool.exe (located in the Jdk_xx\jre\bin directory), as follows:

Keytool-genkey-alias mykey-keyalg rsa-validity 40000-keystore demo.keystore# Description: #    -genkey generate key #    -alias MyKey Name mykey#    -keyalg RSA uses RSA algorithm to sign encryption #    -validity 40000 expiration 4,000 days #    -keystore Demo.keystore
Sign the APK

Use the resulting keystore to sign the APK, using the Jarsigner.exe, which is located in the Jdk_xx\bin directory, the command is as follows:

Jarsigner-verbose-keystore Demo.keystore-signedjar test_signed.apk test.apk mykey#    test_signed.apk is the file after signature #    test.apk is a file that needs to be signed

It is also important to note that if your JDK version is above 1.7, you will need to add this parameter when you sign the APK:

-digestalg Sha1-sigalg Md5withrsa

Otherwise the same will occur: Failure [install_parse_failed_no_certificates] error.

View signature Information

1. View KeyStore Information

Keytool-list-keystore Demo.keystore-alias Mykey-v

2. View KeyStore's public key certificate information

Keytool-list-keystore Demo.keystore-alias MYKEY-RFC

(Note: Obtain a public key certificate in the BASE64 format, RFC 1421)

3. Check the APK signature information

Jarsigner-verify-verbose-certs <your_apk_path.apk>

Android signature mechanism: Generate KeyStore, sign, view signature information

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.