Exemplo n.º 1
0
        static LisenceHelper()
        {
            //解析Lisence
            //本机机器码
            string serialNo = WMIHelper.GetDiskSerialNumber() + WMIHelper.GetCPUSerialNumber();

            if (serialNo.Length >= 24)
            {
                LocalMachineNumber = serialNo.Substring(0, 24);
            }
            else
            {
                LocalMachineNumber = serialNo.PadRight(24 - serialNo.Length, '0');
            }
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lisence");

            if (File.Exists(fileName) == false)
            {
                IsLisenceFileExist = false;
                return;
            }
            IsLisenceFileExist = true;
            string resutl = "";

            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                byte[] data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                resutl = Encoding.UTF8.GetString(data);
            }
            string  json       = RSAHelper.PublicKeyDecrypt(xmlPublicKey, resutl);
            object  objLicense = JsonConvert.DeserializeObject(json);
            JObject jobj       = objLicense as JObject;

            Type          = jobj["Type"].ToString();
            MachineNumber = jobj["MachineNumber"].ToString();
            ExpiredDate   = jobj["ExpiredDate"].ToString();
            CreationDate  = jobj["CreationDate"].ToString();
        }