Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Obfuscator.cs 1.7KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace UnityEngine.Purchasing.Security
  5. {
  6. /// <summary>
  7. /// This class will deobfuscate the tangled signature used for client-side receipt validation obfuscation.
  8. /// </summary>
  9. public static class Obfuscator
  10. {
  11. /// <summary>
  12. /// Deobfucscates tangle data.
  13. /// </summary>
  14. /// <param name="data"> The Apple or GooglePlay public key data to be deobfuscated. </param>
  15. /// <param name="order"> The array of the order of the data slices used to obfuscate the data when the tangle files were originally generated. </param>
  16. /// <param name="key"> The encryption key to deobfuscate the tangled data at runtime, previously generated with the tangle file. </param>
  17. /// <returns>The deobfucated public key</returns>
  18. public static byte[] DeObfuscate(byte[] data, int[] order, int key)
  19. {
  20. var res = new byte[data.Length];
  21. int slices = data.Length / 20 + 1;
  22. bool hasRemainder = data.Length % 20 != 0;
  23. Array.Copy(data, res, data.Length);
  24. for (int i = order.Length - 1; i >= 0; i--)
  25. {
  26. var j = order[i];
  27. int sliceSize = (hasRemainder && j == slices - 1) ? (data.Length % 20) : 20;
  28. var tmp = res.Skip(i * 20).Take(sliceSize).ToArray(); // tmp = res[i*20 .. slice]
  29. Array.Copy(res, j * 20, res, i * 20, sliceSize); // res[i] = res[j*20 .. slice]
  30. Array.Copy(tmp, 0, res, j * 20, sliceSize); // res[j] = tmp
  31. }
  32. return res.Select(x => (byte)(x ^ key)).ToArray();
  33. }
  34. }
  35. }