FairGuard.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Text;
  8. using System.Security.Cryptography;
  9. using System;
  10. public static class FairGuard{
  11. private static bool isInitialized = false;
  12. private const string version = "7.1.6";
  13. private const string strUUU_0 = "Ce90DysQNIJUCHKmRNU3D5iWaTALey+dzOzyfv8CUnjUI06FmqEiozthUnmjKuHM2xULzwMWetEtieUBfjKNvQ==";
  14. private const string strHHH_0 = "8WXEpyGHQhkngJnHyBoGS4boUvmc4UFlZxs/auPu58qy7/WHv2CfVz6O9bfL+rpivAB7z4hIILTgz4nwtHLIGw==";
  15. private const string strIII_0 = "e6WqwzKWyswU8joVaNYOnA==";
  16. private const string strSSS_0 = "5OXMqsdS0ZtPf7WWtwlgB6e7yFUhXSVdytweVgUEXsA=";
  17. private const string strXXX_0 = "5OXMqsdS0ZtPf7WWtwlgB+QOgX9ubkaYohDeyjjyBg0=";
  18. private const string strGGG_0 = "beI2N5JQWRyEY5Lar9eMsFvzJtrK0L+UafGyP1zk3vo=";
  19. private const string strNNN_0 = "UxJvtb7ND3kpYAUPpmwhtQ==";
  20. private const string strRRR_0 = "LHSIOoMn0jmrAPNRyN4BkmWFUk5S6PF2NynQ+o3kMUI=";//getUltraSign
  21. private static string strUUU = "";
  22. private static string strHHH = "";
  23. private static string strIII = "";
  24. private static string strSSS = "";
  25. private static string strXXX = "";
  26. private static string strGGG = "";
  27. private static string strNNN = "";
  28. private static string strRRR = "";
  29. private static AndroidJavaClass g_SWPClass = null;
  30. public static string Decrypt(string cipherText)
  31. {
  32. string EncryptionKey = "f7f8edd10906b53544";
  33. cipherText = cipherText.Replace(" ", "+");
  34. byte[] cipherBytes = Convert.FromBase64String(cipherText);
  35. using (Aes encryptor = Aes.Create())
  36. {
  37. Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0xf6, 0x92, 0x90, 0x8c, 0x7f, 0x23, 0x4f, 0xc9, 0x13, 0x2d, 0x56, 0x3d, 0x66 });
  38. encryptor.Key = pdb.GetBytes(32);
  39. encryptor.IV = pdb.GetBytes(16);
  40. using (MemoryStream ms = new MemoryStream())
  41. {
  42. using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
  43. {
  44. cs.Write(cipherBytes, 0, cipherBytes.Length);
  45. cs.Close();
  46. }
  47. cipherText = Encoding.Unicode.GetString(ms.ToArray());
  48. }
  49. }
  50. return cipherText;
  51. }
  52. public static void Init()
  53. {
  54. if (isInitialized)
  55. {
  56. return;
  57. }
  58. #if UNITY_ANDROID
  59. strUUU = Decrypt (strUUU_0);
  60. strHHH = Decrypt (strHHH_0);
  61. strIII = Decrypt (strIII_0);
  62. strSSS = Decrypt (strSSS_0);
  63. strXXX = Decrypt (strXXX_0);
  64. strGGG = Decrypt (strGGG_0);
  65. strNNN = Decrypt (strNNN_0);
  66. strRRR = Decrypt (strRRR_0);
  67. try
  68. {
  69. using (var actClass = new AndroidJavaClass(strUUU))
  70. {
  71. g_SWPClass = new AndroidJavaClass(strHHH);
  72. }
  73. }
  74. catch (System.Exception e)
  75. {
  76. System.Console.Write(" " + e.ToString());
  77. }
  78. initSDK("");
  79. #endif
  80. isInitialized = true;
  81. }
  82. private static void initSDK(string gameKey)
  83. {
  84. #if UNITY_ANDROID
  85. if (g_SWPClass != null)
  86. {
  87. g_SWPClass.CallStatic(strIII, gameKey);
  88. }
  89. #endif
  90. }
  91. #if UNITY_IPHONE && !UNITY_EDITOR
  92. [DllImport ("__Internal")]
  93. public static extern void setUserInfo(string roleName, string roleAccount,string roleId);
  94. #else
  95. public static void setUserInfo(string roleName, string roleAccount,string roleId)
  96. {
  97. #if UNITY_ANDROID
  98. if (g_SWPClass != null)
  99. {
  100. g_SWPClass.CallStatic(strSSS, roleName, roleAccount, roleId);
  101. }
  102. #endif
  103. }
  104. #endif
  105. #if UNITY_IPHONE && !UNITY_EDITOR
  106. [DllImport ("__Internal")]
  107. public static extern void setUserInfoEx(string roleName, string roleAccount,string roleId, String serverName, String channelName, string gameJson);
  108. #else
  109. public static void setUserInfoEx(string roleName, string roleAccount,string roleId, String serverName, String channelName, string gameJson)
  110. {
  111. #if UNITY_ANDROID
  112. if (g_SWPClass != null)
  113. {
  114. g_SWPClass.CallStatic(strXXX, roleName, roleAccount, roleId, serverName, channelName, gameJson);
  115. }
  116. #endif
  117. }
  118. #endif
  119. #if UNITY_IPHONE && !UNITY_EDITOR
  120. [DllImport ("__Internal")]
  121. public static extern string setGuardId(int guardId);
  122. #else
  123. public static string setGuardId(int guardId)
  124. {
  125. string strRet="";
  126. #if UNITY_ANDROID
  127. if(g_SWPClass!=null)
  128. {
  129. strRet = g_SWPClass.CallStatic<string>(strGGG, guardId);
  130. }
  131. #endif
  132. return strRet;
  133. }
  134. #endif
  135. public static string getSign(String inputData)
  136. {
  137. string strRet = "";
  138. #if UNITY_ANDROID
  139. if (g_SWPClass != null)
  140. {
  141. strRet = g_SWPClass.CallStatic<string>(strNNN, inputData);
  142. }
  143. #endif
  144. return strRet;
  145. }
  146. public static string getUltraSign(String inputData)
  147. {
  148. string strRet = "";
  149. #if UNITY_ANDROID
  150. if (g_SWPClass != null)
  151. {
  152. strRet = g_SWPClass.CallStatic<string>(strRRR, inputData);
  153. }
  154. #endif
  155. return strRet;
  156. }
  157. }