Hi guys.
I have issue. When I get signature and signedData from google play to send gamespark. I received error {“storeError”:“java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Short read of DER length”,“verificationError”:“2”}". I know “verificationError”:"2 means The signature does not match the signed data. How can I fix this?
The class below I used get INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE:
class GooglePurchaseData {
// INAPP_PURCHASE_DATA
public string inAppPurchaseData;
// INAPP_DATA_SIGNATURE
public string inAppDataSignature;
[System.Serializable]
private struct GooglePurchaseReceipt { public string Payload; }
[System.Serializable] private struct GooglePurchasePayload {
public string json; public string signature;
}
public GooglePurchaseData(string receipt) {
try {
var purchaseReceipt = JsonUtility.FromJson (receipt);
var purchasePayload = JsonUtility.FromJson purchaseReceipt.Payload);
inAppPurchaseData = purchasePayload.json;
inAppDataSignature = purchasePayload.signature;
} catch {
Debug.Log("Could not parse receipt: " + receipt);
inAppPurchaseData = “”; inAppDataSignature = “”;
}
}
}
Sorry, we would not be familiar with how Gamespark is parsing the receipts or the format they expect. You are parsing the receipt, cannot you just get send the receipt directly? And I don’t follow this code, you aren’t returning anything from the method. I trust that you are not just updating global variables.
public GooglePurchaseData(string receipt) {
try {
var purchaseReceipt = JsonUtility.FromJson (receipt);
var purchasePayload = JsonUtility.FromJson purchaseReceipt.Payload);
inAppPurchaseData = purchasePayload.json;
inAppDataSignature = purchasePayload.signature;
} catch {
Debug.Log("Could not parse receipt: " + receipt);
inAppPurchaseData = “”; inAppDataSignature = “”;
}
Thank for reply me, I try log signature and signedData from receipt and I received : example: signature: bz/IvIc/MNIerWxBh0RgQqTTTbnMwlBBvqIlfSpkhjJh88Wm8iEismgNiMwhKiubzPcWdHOqLDoLWAMsEhkNUQ5oGYI8d1DI2ZAeuPXUq2D51AJ18wcILPuNYlygqXXJyvdolk9XLSLRSiJ/25WeI8yNcQir2Fmn6Fp8Xq9hhhPHvD+pyHEmIp1DAbccH2U+eKar2TNTnlyxXNAtlJB8ytE9CcvDjfx6yu7evpWJEKH13o86LMT4mBFP79a8OVaxoNVTqr+P7I0Ej+t9D4HjC0fEMhAM/nuw1bWmAKPJmZ75wvYYOSJuiSMSqPgUknGdYlP86Mjl2hVja9CoB9C8mg==
signedData : {“orderId”:“GPA.3397-7552-1832-86713”,“packageName”:“xxxxxxxxxxx.xxx.xxxx”,“productId”:“xxxx”,“purchaseTime”:1590593595122,“purchaseState”:0,“developerPayload”:“{"developerPayload":"","is_free_trial":false,"has_introductory_price_trial":false,"is_updated":false,"accountId":""}”,“purchaseToken”:“glgocgpfgnofjjfobegfdnaf.AO-J1OxyrvGGGZ9Z6A72SOJiHFhk9FH6gWSM8xcwmWydBgL-D4wWSZlC5_KcnfcWqmHbyE7R5MAOT6NKdOMBdT5AzraU1YSeilJrwZfKzIPX1UVNpqxNbEQlsgLAmG6hnjsqMD2215mIzTFJah9GJO4XihlOdyxMUw”}
but when I send to gamespark with code:
GooglePurchaseData data = new GooglePurchaseData(product.receipt);
new GameSparks.Api.Requests.GooglePlayBuyGoodsRequest()
.SetSignature(signature)
.SetSignedData(signedData )
.Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log(“Successful purchase”);
}
else
{
Debug.Log("Purchase error: " + response.Errors.JSON);
}
});
I received response: {“storeError”:“java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Short read of DER length”,“verificationError”:“2”}
I follow with code of Martin Wellman this link: https://support.gamesparks.net/support/discussions/topics/1000069462
Sorry, we would not be able to assist, not familiar. It may be those / escape characters, you might need to remove those. One note, that article you referred to is using native API programming, not Unity IAP. You can use this for receipt verification with Unity IAP
Note the e.purchasedProduct.receipt property