Android应用内计费错误InvalidKeySpecException
我正在尝试使用Trial Gas教程的包装器实现应用内购买。成功购买完成后,应用程序崩溃,从那时起,应用程序开始崩溃Android应用内计费错误InvalidKeySpecException,android,runtime-error,in-app-billing,Android,Runtime Error,In App Billing,我正在尝试使用Trial Gas教程的包装器实现应用内购买。成功购买完成后,应用程序崩溃,从那时起,应用程序开始崩溃 java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long at com.nightowl.memo
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
我使用了以下代码来调用它:
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
}
}
};
字符串base64EncodedPublicKey;
base64EncodedPublicKey=String.valueOf(R.String.myPubKey);
additionalSkuList=新的ArrayList();
对于(int i=0;i不要使用String.valueOf(R.String.myPubKey)
,它会给你一个错误的值。相反,使用getResources().getString(R.String.myPubKey\u data))
来获取你的公钥字符串。虽然这个问题很老,但我为任何人写的答案都会有这个问题。
问题在于公钥长度。它无效,并且比应该的长。请确保输入正确。Security.generatePublicey出现错误。如果我在verifyPurchase函数中对其进行注释并强制发送true,那么代码将正常运行。知道为什么会这样吗?我将pubkey定义为一个字符串(我自己没有编码或解码密钥(我发现在解决类似问题时没有这样做))。但我还是犯了同样的错误。你解决了这个问题吗?我的应用程序经常会以1星的速率出现这个错误。这只虫子让我发疯*(