Add RSA signature to App

Source: Internet
Author: User
Tags android sdk manager

RSA signature, Google is primarily used for app source control and billing. The so-called settlement, is also the control of the app only use the current machine on the login Google account from the Google market has downloaded the app to be able to use, so it has reached the purpose of the app sales.

The addition of RSA signatures is mainly divided into the following steps 1). Add License Verification Library (LVL) 2). Publish a beta version to the Google Play market. 3). Implement the signature authentication function in the code and control the permissions of the app. All of the following actions are done in Android studio. Eclipse can be used for reference. One. Add a third-party library license Verification Library (LVL) Step 1, download the LVL Gallery to open the Android SDK Manager. Locate the Google Play LIcensing library below the library list extras. Download it. Now complete the Lib will be stored in android-sdk-windows\extras\google\play_licensing\library. 2, add the LVL library to the project file---New---Import Module. Select the LVL library in the SDK. That's android-sdk-windows\extras\google\play_licensing\library. Select correct, the module Name will appear. This lib name can be customized. This is defined as LVL. 3. Open the app's grade file. Note: The grade File is in the app directory. The general name is Build.grade. corresponding location (dependencies) added
Compile project (': Lvl ')
4, click Tools----Android-----Sync Project with Grade Files. Completed the addition of third-party libraries. Add a third-party library method reference: http://www.truiton.com/2015/02/android-studio-add-library-project/two. Publish a beta version to the Google market this step is the same as the normal release of an app. Only when the APK upload, the choice is the beta version, the informal version. Note: Click on the top right corner of the post is complete, not upload the APK even after completion. The test app needs to add a test account to the closed test list, which means that the mobile phone is now signed in to the Google account that needs to be added or not tested. Third, the realization of the interaction with the signature server to achieve control of the application of the control of the permissions of the official operation method reference: http://developer.android.com/google/play/licensing/adding-licensing.html #impl-obfuscator interacts primarily with the signature server by Licensechecker this class. The purpose of controlling the app is to register a Licensecheckercallback callback via Licensechecker, which is usually done in mainactivity with the signature server.    In Mlicensecheckercallback, if the successful authentication app continues to go down, you may be prompted to exit. Here's how: 1, add app permissions
<android:name= "Com.android.vending.CHECK_LICENSE"/>
2, the mainactivity defines an array of 20 random bytes (for aesobfuscator use), and some variables.
Private Static FinalString Base64_public_key = " miibijanbgkqhkig9w0baqefaaocaq8amiibcgkcaqeajynfykmkhwauvkl22muo3z2hktxbtxzjaktr1xriaudsnwcywkoaewssgccs+ koineytk1/ampbwfhjqul08atmaygaukofd3oltfkan4at99ajh9bxknwzclaailt7jw1+ 8poiaintllhzpyg2c6vqset2vrygcfcxzkq9bnnhjqkgxjagsrf43whfxhl1nuedddm4ddmgjaegy2loglrbyq9cuqxsgn8t1c/ebye2izn+ Ojtg0/9+ce6wwgabetyqi3hvcvwertvywt8pazujcx6epvhtl3jfvp73qewojr381e8fpsw+qvd+2rnsznphbsy56f/4wg4ohpgg6twidaqab ";Private Static Final byte[] SALT =New byte[] {13, 32, 81, 65, 53, 82, 18, 100,-69,-17, 51, 81,-13, 86,-10,-40, 19, 45, 63,-7 };PrivateLicensechecker Mchecker;PrivateLicensecheckercallback Mlicensecheckercallback;

3. Define an internal Licensecheckercallback class
Private classMylicensecheckercallbackImplementsLicensecheckercallback {@Override Public voidAllowintreason) {    //log.i ("RSA", "Success Code:" + reason);delayedhide (Hide_delay_millis); } @Override Public voidApplicationerror (intErrorCode) {    //log.i ("RSA", "Error Code:" + errorCode);havenolicence (); } @Override Public voidDontallow (intreason) {LOG.I ("RSA", "Dontallow Code:" +reason); if(Reason!=policy.licensed) {//Not successhavenolicence (); }    }} 

In this callback class, the Access return method is Dontallow. Allow is called in case of success. The case of error will be called Applicationerror, error does not include no license, network errors and so on. So here I am directly without the authentication successfully execute the method without permission. 4, initialize Licensechecker and Licensecheckercallback
String deviceId = Settings.Secure.getString (Getcontentresolver (), Settings.Secure.ANDROID_ID); // Library calls this when it's done. New Mylicensecheckercallback (); // Construct the Licensechecker with a policy. New Licensechecker (Thisnew servermanagedpolicy (Thisnew aesobfuscator (SALT, Getpackagename (), deviceId)), Constants.rsa_key);
5, access the signature server for verification.
Mchecker.checkaccess (Mlicensecheckercallback);

Here, the RSA certification has been completed. You may encounter issues 1, error, error code 3. is because the Google market does not upload apk. Or it hasn't been published yet. If you have finished publishing, please wait for approval. An estimate can be approved within 24 hours. 2. Switch to the Google Account or replace the RSA KEY in the app. If the results of the validation are not the same as the imagined results, you need to remove the app and restart your phone before testing. 3, the list of other error codes is as follows:
LICENSED = hex:0x0100, decimal:256= hex:0x0231, decimal:561= hex:0x0123, decimal:291= Hex : 0x2, decimal:2= hex:0x3, decimal:3= hex:0x4, decimal:4= hex:0x5, decimal:5= H ex:0x101, decimal:257= hex:0x102, decimal:258= hex:0x103, decimal:259

Source: >  

Add RSA signature to App

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.