private T DecryptResponse <T>(InputSyncData encryptedData) { CryptoUtils.SecretAESKey dataKey = CryptoUtils.DecryptSecretAESKey(privateKey, encryptedData.Key); T decryptData = CryptoUtils.DecryptDataAES <T>(dataKey, encryptedData.Code); return(decryptData); }
public async void Sync() { List <InputInfo> syncDataList = new List <InputInfo>(); (privateKey, publicKey) = CryptoUtils.GenerateRSAKeys(); using (var db = new RaidaContext()) { OneTableHash actualInfo = new OneTableHash() { PublicKey = publicKey }; await db.Members.Include(it => it.MemberInGroup).ForEachAsync(it => { actualInfo.ActualMembers.Add(GetHash(it)); }); await db.Groups.ForEachAsync(it => { actualInfo.ActualGroups.Add(GetHash(it)); }); await db.MemberInGroup.ForEachAsync(it => { actualInfo.ActualMinG.Add(GetHash(it)); }); try { foreach (string serverUrl in MainConfig.TrustedServers) { InputSyncData responseMember = await $"{serverUrl}/api/sync".PostJsonAsync(actualInfo).ReceiveJson <InputSyncData>(); InputInfo tmpInfo = DecryptResponse <InputInfo>(responseMember); tmpInfo.ServerURL = serverUrl; syncDataList.Add(tmpInfo); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; //Console.WriteLine(ex.Message); Console.WriteLine("Error of synchronize data from trust server"); Console.ResetColor(); Console.ReadLine(); } if (syncDataList.Count > 0) { InputInfo correctData = IntersectData(syncDataList); SyncronizeBase(correctData, db); DetectIncorrectServer(correctData, syncDataList); } } }