Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android InAppBilling - Invalid Key Spec Exception

I have been working on an application that has very basic InAppBilling needs (user can purchase a 1-time upgrade to the app). I've run into an issue during testing that has confounded me.

After successfully testing with android.test.purchase I moved on to testing with the real item (as a licence tester in the console). I purchased the item successfully.

I then restarted the application - only to be greeted with an error that is triggered when I call "queryInventoryAsync":

03-12 14:22:51.795  15607-15632/com.mybodyjourney.mybodyjourney E/IABUtil/Security﹕ Invalid key specification.
03-12 14:22:51.795  15607-15632/com.mybodyjourney.mybodyjourney W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x4193dce0)
03-12 14:22:51.825  15607-15632/com.mybodyjourney.mybodyjourney E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-1176
Process: com.mybodyjourney.mybodyjourney, PID: 15607
java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
        at com.mybodyjourney.mybodyjourney.util.Security.generatePublicKey(Security.java:91)
        at com.mybodyjourney.mybodyjourney.util.Security.verifyPurchase(Security.java:71)
        at com.mybodyjourney.mybodyjourney.util.IabHelper.queryPurchases(IabHelper.java:869)
        at com.mybodyjourney.mybodyjourney.util.IabHelper.queryInventory(IabHelper.java:544)
        at com.mybodyjourney.mybodyjourney.util.IabHelper.queryInventory(IabHelper.java:522)

This was after no change to the codebase.

I then deployed the same code to a different device. First time running it ran fine (no errors) and informed me that I'd already purchased the item (which was correct).

Then I closed and re-opened the app on this second device, and was immediately greeted with the same error as the original device.

Any help would be greatly appreciated as I am unable to find anyone who's successfully solved this issue online.

like image 684
Mark Cracknell Avatar asked Apr 15 '26 13:04

Mark Cracknell


1 Answers

So it turns out I had made an error in my code (surprise surprise). The error I made was in the definition of my public key string (I had run Base64.encode over the already encoded string).

What threw me was the fact that up until the first time I actually purcahsed an item - Google's services all acted and worked perfectly. At no point did it ever complain about the key.

This would suggest that something wasn't finalised with the developer account until the first purchase?

Either way, everything is now resolved.

like image 190
Mark Cracknell Avatar answered Apr 17 '26 04:04

Mark Cracknell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!