public static async Task IdentifyAsync() { var req = WebRequest.CreateHttp("https://tis.i3panacea.com/PUTIK/request/"); req.Method = "POST"; req.ContentType = "application/json"; req.Accept = "application/json"; req.Timeout = 20000; var macs = Common.GetAllMacAddresses(); var driveSerials = CpuID.GetAllDiskDrives().ToList(); var suggestedId = CpuID.ProcessorId(); using (var rsa = new RSACryptoServiceProvider(1024)) { dynamic obj = new { MACs = macs, HDIDs = driveSerials, CPUID = suggestedId, publicKey = ExportPublicKey(rsa), computerName = Environment.MachineName }; using (var writer = new StreamWriter(req.GetRequestStream())) { writer.Write(JsonSerializer.SerializeToString(obj)); } using (var resp = await req.GetHttpResponseAsync(20000)) using (var reader = new StreamReader(resp.GetResponseStream())) using (var writer = new StreamWriter(_fileName)) { var json = await reader.ReadToEndAsync(); var dobj = JsonObject.Parse(json); _identificationInfo = new IdentificationInfo() { Putik = dobj.Get <string>("PUTIK"), PublicKey = ExportPublicKey(rsa), PrivateKey = ExportPrivateKey(rsa) }; writer.Write(JsonSerializer.SerializeToString(_identificationInfo)); } } }
public static async Task <IdentificationInfo> GetIdentificationInfoAsync() { if (_identificationInfo != null) { return(_identificationInfo); } if (File.Exists(_fileName)) { using (var reader = new StreamReader(_fileName)) { var json = await reader.ReadToEndAsync(); _identificationInfo = JsonSerializer.DeserializeFromString <IdentificationInfo>(json); return(_identificationInfo); } } return(null); }