标签:
RSA签名,Google主要用于APP的来源控制与结算。所谓的结算,也是就是控制了APP只有使用现在机子上登录的Google账户从Google市场曾经下载过该APP的才能够使用,这样也就达到了app销售的目的。
compile project(‘:lvl‘)
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
private static final String 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 }; private LicenseChecker mChecker; private LicenseCheckerCallback mLicenseCheckerCallback;
private class MyLicenseCheckerCallback implements LicenseCheckerCallback { @Override public void allow(int reason) { // Log.i("RSA", "success Code: " + reason); delayedHide(HIDE_DELAY_MILLIS); } @Override public void applicationError(int errorCode) { // Log.i("RSA", "Error Code: " + errorCode); haveNoLicence(); } @Override public void dontAllow(int reason) { Log.i("RSA", "dontAllow Code: " + reason); if (reason !=Policy.LICENSED){ //not success haveNoLicence(); } } }
String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); // Library calls this when it‘s done. mLicenseCheckerCallback = new MyLicenseCheckerCallback(); // Construct the LicenseChecker with a policy. mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), Constants.RSA_KEY);
mChecker.checkAccess(mLicenseCheckerCallback);
LICENSED = Hex: 0x0100, Decimal: 256 NOT_LICENSED = Hex: 0x0231, Decimal: 561 RETRY = Hex: 0x0123, Decimal: 291 LICENSED_OLD_KEY = Hex: 0x2, Decimal: 2 ERROR_NOT_MARKET_MANAGED = Hex: 0x3, Decimal: 3 ERROR_SERVER_FAILURE = Hex: 0x4, Decimal: 4 ERROR_OVER_QUOTA = Hex: 0x5, Decimal: 5 ERROR_CONTACTING_SERVER = Hex: 0x101, Decimal: 257 ERROR_INVALID_PACKAGE_NAME = Hex: 0x102, Decimal: 258 ERROR_NON_MATCHING_UID = Hex: 0x103, Decimal: 259
标签:
原文地址:http://www.cnblogs.com/fengyun1989/p/4883009.html