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