In-App Billing Error InvalidKeySpecException

I am trying to implement an in-app purchase using the cover of the Trivial Gas tutorial. After the successful purchase, the application crashed, since then the application begins to break from the very beginning.

java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.nightowl.memory.Security.generatePublicKey(Security.java:85)
at com.nightowl.memory.Security.verifyPurchase(Security.java:65)
at com.nightowl.memory.IabHelper.queryPurchases(IabHelper.java:875)
at com.nightowl.memory.IabHelper.queryInventory(IabHelper.java:550)
at com.nightowl.memory.IabHelper.queryInventory(IabHelper.java:528)
at com.nightowl.memory.IabHelper$2.run(IabHelper.java:623)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:101)
at com.android.org.conscrypt.OpenSSLRSAKeyFactory.engineGeneratePublic(OpenSSLRSAKeyFactory.java:47)
at java.security.KeyFactory.generatePublic(KeyFactory.java:171)
at com.nightowl.memory.Security.generatePublicKey(Security.java:80)
... 6 more
Caused by: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.android.org.conscrypt.NativeCrypto.d2i_PUBKEY(Native Method)
at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:99)
... 9 more

I used the following code to call it:

    String base64EncodedPublicKey;
            base64EncodedPublicKey= String.valueOf(R.string.myPubKey);
            additionalSkuList = new ArrayList<String>();
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<4;j++)
                {
                    if(i==0&&j>1)
                        break;
                    additionalSkuList.add(id[i][j]);
                }
            }
            mHelper = new IabHelper(this, base64EncodedPublicKey);
            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                public void onIabSetupFinished(IabResult result) {
                    Log.d("main", "m here");
                    if (!result.isSuccess()) {
                        // Oh noes, there was a problem.
                        Log.d("main", "Problem setting up In-app Billing: " + result);
                    }
                    // Hooray, IAB is fully set up!
                    isIAB = true;

                    mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
                    Log.d("main", "" + isIAB + " " + isLoad);
                }
            });


IabHelper.QueryInventoryFinishedListener
            mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory)
        {
            Log.d("main", "m here too");
            if (result.isFailure()) {
                // handle error
                return;
            }
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<4;j++)
                {
                    if(i==0&&j>1)
                        break;
                    price[i][j]=inventory.getSkuDetails(id[i][j]).getPrice();
                }
            }
            isLoad=true;
            data.setPrice(price);
            data.setDataLoad(true);
            // update the UI
        }
    };

    public void onPurchaseCall()
    {
        int loc[] = data.getItem();
        mHelper.launchPurchaseFlow(this, id[loc[0]][loc[1]], 100*loc[0]+loc[1],mPurchaseFinishedListener, id[loc[0]][loc[1]]);
    }
    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
            = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase)
        {
            if (result.isFailure()) {
                Log.d("main", "Error purchasing: " + result);
                return;
            }
            else if (purchase.getSku().equals(id[0][0])) {
                data.setNoads(1);
                mAdView.setVisibility(View.INVISIBLE);
                data.setNotificationState(1);
                data.setNoOfnotifications(2);
                data.setNotificationMsg(0, "Purchase Complete");
                data.setNotificationMsg(1, PurchaseMsg[0]);
                // consume the gas and update the UI
            }


        }
    };

Can someone help me solve this problem? What I guessed from the log is the public key issue that I provide. But the first time he worked (he worked until I started a successful purchase). And I also get a price list of all my products in the application.

I tried to verify the purchase using a test account. Upon successful completion of the purchase, this error appeared, and since then the application does not work for this account.

+4
2

String.valueOf(R.string.myPubKey), . getResources().getString(R.string.myPubKey_data)), .

0

, , - . . , . , .

0

Source: https://habr.com/ru/post/1606184/


All Articles