Exemple #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (true)
            {
                if (stoppingToken.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    var data = await v2rayService.QueryV2RayDataAsync();

                    string json  = JsonConvert.SerializeObject(data);
                    byte[] bytes = Encoding.UTF8.GetBytes(json);
                    RandomNumberGenerator numberGenerator = RandomNumberGenerator.Create();
                    byte[] keyData = new byte[32];
                    numberGenerator.GetBytes(keyData);
                    KeyParameter key         = new KeyParameter(keyData);
                    byte[]       encrytpo    = symmetric.Encrypto(bytes, key);
                    byte[]       keyEncrypto = asymmetric.Encrypto(key.GetKey(), parameter);
                    using (MultipartFormDataContent content = new MultipartFormDataContent())
                        using (ByteArrayContent sdata = new ByteArrayContent(encrytpo))
                            using (ByteArrayContent skeyData = new ByteArrayContent(keyEncrypto))
                            {
                                sdata.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
                                skeyData.Headers.ContentType     = new MediaTypeHeaderValue("application/octet-stream");
                                sdata.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                                {
                                    FileName = "encodedData",
                                    Name     = "data",
                                };
                                skeyData.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                                {
                                    FileName = "dekey",
                                    Name     = "key"
                                };
                                content.Add(sdata);
                                content.Add(skeyData);
                                await http.PostAsync("/api/data", content);
                            }
                }
                catch { }
                Thread.Sleep(600000); // 10分钟
            }
        }