private bool isLicenseForCurrentMachine(string license, string appId) { IntPtr licensePtr = IntPtr.Zero; try { byte[] licenseData = Convert.FromBase64String(license); licensePtr = Marshal.AllocHGlobal(licenseData.Length); Marshal.Copy(licenseData, 0, licensePtr, licenseData.Length); foreach (string hdId in EncryptHelper.GetHardwareIdMD5()) { IntPtr hdIdPtr = Marshal.StringToHGlobalAnsi(hdId); int nRet = LicenseAPI.IsLicenseForCurrentMachine(licensePtr, licenseData.Length, hdIdPtr); Marshal.FreeHGlobal(hdIdPtr); if (nRet != 0) { return(true); } } } finally { if (licensePtr != IntPtr.Zero) { Marshal.FreeHGlobal(licensePtr); } } return(false); }
public bool IsTrialVersion(string gadgetId) { string encryptGadgetId = EncryptHelper.GetMD5Hash(gadgetId); if (this.gadgetLicenseDictionary.ContainsKey(encryptGadgetId)) { string licenseString = this.gadgetLicenseDictionary[encryptGadgetId]; byte[] licenseData = Convert.FromBase64String(licenseString); IntPtr licensePtr = Marshal.AllocHGlobal(licenseData.Length); Marshal.Copy(licenseData, 0, licensePtr, licenseData.Length); return(LicenseAPI.IsTrialVersion(licensePtr, licenseData.Length) != 0); } return(false); }
internal static IEnumerable <string> DecryptLicenseFile(string decryptString) { string decryptKey = string.Empty; foreach (char c in GetLicensePassword()) { decryptKey += c; } byte[] passwordData = Convert.FromBase64String(decryptKey); IntPtr passwordPtr = Marshal.AllocHGlobal(passwordData.Length); Marshal.Copy(passwordData, 0, passwordPtr, passwordData.Length); IntPtr decryptPtr = LicenseAPI.DecryptPassword(passwordPtr, passwordData.Length); Marshal.FreeHGlobal(passwordPtr); byte[] decryptData = new byte[8]; Marshal.Copy(decryptPtr, decryptData, 0, 8); decryptKey = Encoding.ASCII.GetString(decryptData); byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey); List <byte> rgbIVList = new List <byte>(); foreach (byte key in GetKeys()) { rgbIVList.Add(key); } byte[] rgbIV = Enumerable.ToArray <byte>(rgbIVList); byte[] inputByteArray = Convert.FromBase64String(decryptString); DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider(); MemoryStream mStream = new MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); string ret = Encoding.UTF8.GetString(mStream.ToArray()); cStream.Close(); mStream.Close(); yield return(ret); }