Skip to content

Commit

Permalink
Google Play - quick change for public key
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed May 5, 2017
1 parent a939a29 commit de0eee6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
18 changes: 3 additions & 15 deletions Xamarin.InAppPurchasing.Droid/Models/GooglePlayPurchaseService.cs
Expand Up @@ -57,19 +57,7 @@ public void Disconnect()
}
}

public string PublicKey1 { get; set; }

public string PublicKey2 { get; set; }

public string PublicKey3 { get; set; }

public static string TransformString(string key, int i)
{
var chars = key.ToCharArray(); ;
for (int j = 0; j < chars.Length; j++)
chars[j] = (char)(chars[j] ^ i);
return new string(chars);
}
public string PublicKey { get; set; }

public async override Task<Purchase[]> GetPrices(params string[] ids)
{
Expand Down Expand Up @@ -167,12 +155,12 @@ protected async override Task<Receipt> BuyNative(Purchase purchase)

private bool IsSignatureValid(Order order, string orderJson)
{
if (string.IsNullOrEmpty(PublicKey1) || string.IsNullOrEmpty(PublicKey2) || string.IsNullOrEmpty(PublicKey3))
if (string.IsNullOrEmpty(PublicKey))
throw new Exception("PublicKey not set!");

if (_publicKey == null)
{
var bytes = Convert.FromBase64String(TransformString(PublicKey1, 1) + TransformString(PublicKey2, 2) + TransformString(PublicKey3, 3));
var bytes = Convert.FromBase64String(PublicKey);
var keyFactory = KeyFactory.GetInstance("RSA");
_publicKey = keyFactory.GeneratePublic(new X509EncodedKeySpec(bytes));
}
Expand Down
5 changes: 4 additions & 1 deletion Xamarin.InAppPurchasing.Droid/Tests/PurchaseServiceTests.cs
Expand Up @@ -14,7 +14,10 @@ public class PurchaseServiceTests

public PurchaseServiceTests()
{
PurchaseService = new GooglePlayPurchaseService();
PurchaseService = new GooglePlayPurchaseService
{
PublicKey = "YOUR_KEY_HERE",
};
}

[Fact]
Expand Down

0 comments on commit de0eee6

Please sign in to comment.