Exemplo n.º 1
0
        private static void CheckLicense(object o = null)
        {
            try
            {
                const string pubKeyNotXoRed =
                    "<RSAKeyValue><Modulus>wzzpNEbNjAWLI3AgFLb0YZ8gjqqmIgD1rTU3xy25IuetNsA5QKJxP7whwKq2LF4ul56LhxG3M3Wxhr/kZOgXWbPjEG1zyB7Lx83B65z6CFRIV5llzZziq6/uZP2cEHfwF62/letOD+tUaVvsi4/jvVv5NEanfeoXIQ1cbSBuWaEXfNpra48lmAZpTSLu93l9o+ooJsyrwBBHwWrS3/ljE/19PF4SetqNvUi7FpsrtB5emsG26M7AYiEv/lN2oJlOMU4+yJa/na+LZEdjSsG7yUiSTu2r23ixQlfKbGLwCDtP3VLgf2wrptq7KCIaYrQIznl/kON7CeHT10kKvcjAPQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
                var curRandom = new Random();
                var preKey    = RandomStringWithNumbers(curRandom.Next(15, 21), curRandom);
                var xoRkey    = curRandom.Next(1, int.MaxValue);
                var pubKey    = DigitalSign.Xor(pubKeyNotXoRed, xoRkey);

                var token         = curRandom.Next(1000000, int.MaxValue);
                var infoXoRed     = DigitalSign.Xor(Info(token, preKey), xoRkey);
                var responseXoRed =
                    DigitalSign.Xor(
                        GetRequest(DigitalSign.Xor(infoXoRed, xoRkey)), xoRkey);
                var responseSplitted = DigitalSign.Xor(responseXoRed, xoRkey)
                                       .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                if (responseSplitted[0].Split('=')[1] == "1")
                {
                    if (int.Parse(DigitalSign.DecryptString(responseSplitted[4], preKey)) != token)
                    {
                        return;
                    }
                    if (_hwid != Encoding.UTF8.GetString(
                            Convert.FromBase64String(
                                responseSplitted[1].Split(new[] { '[', ']' },
                                                          StringSplitOptions.RemoveEmptyEntries)[0])))
                    {
                        return;
                    }
                    if (!DigitalSign.CompareRsaMethod(GetSignedText(responseSplitted),
                                                      responseSplitted[responseSplitted.Length - 1].Split(new[] { '[', ']' },
                                                                                                          StringSplitOptions.RemoveEmptyEntries)[0], DigitalSign.Xor(pubKey, xoRkey)))
                    {
                        return;
                    }
                    var currentTime   = DateTime.Parse(responseSplitted[2].Split('=')[1]);
                    var endTime       = DateTime.Parse(responseSplitted[3].Split('=')[1]);
                    var activatedTime = endTime.Subtract(currentTime);
                    var timeOffset    = currentTime.Subtract(DateTime.Now);
                    _dt  = endTime - timeOffset;
                    _lic = activatedTime >= TimeSpan.Zero;
                }
                else
                {
                    Register("");
                }
            }
            catch (Exception e)
            {
                if (!_lic)
                {
                    MessageBox.Show(@"Не удается связвться с сервером авторизации");
                    Process.GetCurrentProcess().Kill();
                }
            }
        }
Exemplo n.º 2
0
        private static string Info(int token1, string preKey)
        {
            string tokenString = $"token={DigitalSign.EncryptString(token1.ToString(), preKey)}&key={_hwid}";

            return(tokenString);
        }