/// <summary> /// Update license date and time by user id. /// </summary> /// <param name="id">User id value.</param> /// <param name="newLicenseDate">New license date and time.</param> public void UpdateLicense(int id, DateTime newLicenseDate) { RegisteredUser updatingUser = _db.RegisteredUsers .FirstOrDefault(x => x.Id == id); if (updatingUser == null) { // TODO: Add logging return; } KeyHash keyHash = new KeyHash(); DateTime currentDate = DateTime.Now; updatingUser.RegistrationDate = currentDate; updatingUser.LicenseFinishDate = newLicenseDate; updatingUser.KeyHash = keyHash.Decrypt(JsonConvert.SerializeObject(new UserJson { Name = updatingUser.Name, MacAdress = updatingUser.MacAdress, LicenseFinishDate = newLicenseDate, RegistrationDate = currentDate }), "AssisTant321", "AlphaPeriod"); _db.SaveChanges(); }
public HashMap(int n) { TABLE_SIZE = n; table = new HashNode <K, V> [TABLE_SIZE]; hashFunc = new KeyHash <K>(); keys = new List <K>(); }
/// <summary> /// Add new user to database. /// </summary> /// <param name="registeredUser">Registered user object.</param> /// <returns>Result: true or false.</returns> public bool AddNewUser(RegisteredUser registeredUser) { try { KeyHash keyHash = new KeyHash(); DateTime currentDate = DateTime.Now; registeredUser.RegistrationDate = currentDate; registeredUser.KeyHash = keyHash.Decrypt(JsonConvert.SerializeObject(new UserJson { Name = registeredUser.Name, MacAdress = registeredUser.MacAdress, LicenseFinishDate = registeredUser.LicenseFinishDate, RegistrationDate = currentDate }), "AssisTant321", "AlphaPeriod"); _db.RegisteredUsers.Add(registeredUser); _db.SaveChanges(); return(true); } catch { return(false); } }
/// <summary> /// GetHashCode /// </summary> public override int GetHashCode() { unchecked { var hash = 17; return((hash * 23) + KeyHash.GetHashCode(StringComparison.Ordinal)); } }
public override bool Equals(object obj) { return(obj is IssuerInformation issuer && Name == issuer.Name && KeyHash.SequenceEqual(issuer.KeyHash) && X509AuthorityKeyIdentifier == issuer.X509AuthorityKeyIdentifier && IssuedByPreCertificateSigningCert == issuer.IssuedByPreCertificateSigningCert); }
/// <summary> /// GetHashCode /// </summary> public override int GetHashCode() { unchecked { var hash = 17; return((hash * 23) + KeyHash.GetHashCode()); } }
/// <summary> /// GetHashCode /// </summary> /// <returns></returns> public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 23 + KeyHash.GetHashCode(); return(hash); } }
public IActionResult ChangeKey(ApiKeyItem item) { var hashedKey = KeyHash.GetStringSha256Hash(item.ApiKey); var result = ConfigurationWriter.AddOrUpdateAppSetting("ApiKey", hashedKey); if (!result.Success) { return(NotFound(new StatusMessageResponse <ApiKeyItem>(item, "Failed to write to configuration file"))); } return(Ok(new StatusMessageResponse <ApiKeyItem>(item, "Successfully changed Api Key. Please restart the Webserver for the changes to take affect."))); }
private void ActionTimer_Tick(object sender, EventArgs e) { if (CheckForUpdates() || currentStage == AlicesStages.First) { switch (currentStage) { case AlicesStages.First: FirstStageAlice(); Bridge.OpenA = OpenA; Bridge.P = P; Bridge.G = G; Bridge.LogLbl.Text += $"Пользователь 1 отправляет остаток от деления - 'A' в открытом виде,\r\n а также пару чисел 'p' и 'g' Пользователю 2\r\n"; Bridge.LogLbl.Text += $"A={OpenA}\r\np={P}\r\ng={G}\r\n"; Bridge.LogLbl.Text += $"{new string('-', 50)}\r\n"; Bridge.UpdatesForBob = true; currentStage = AlicesStages.Second; break; case AlicesStages.Second: SecondStageAlice(); KeyLbl.Text += secretKey; Bridge.UpdatesForAlice = false; if (!KeyHash.Equals(Bridge.BobsHash)) { Bridge.LogLbl.Text += "Пользователь 1 отклоняет хеш Пользователя 2\r\n"; } else { Bridge.LogLbl.Text += "Пользователь 1 подтверждает хеш Пользователя 2\r\n"; } Bridge.LogLbl.Text += $"{new string('-', 50)}\r\n"; ActionTimer.Stop(); DecryptBtn.Enabled = true; EncryptBtn.Enabled = true; break; default: throw new Exception(); } } }
static private KeyTable HashToKeyTable(KeyHash hash) { KeyTable result = new KeyTable(); foreach (string key in hash.Keys) { List <List <KeyCode> > outMethods = new List <List <KeyCode> >(); // 書式:A,B|C,D|E|F,G string keyMethod = hash[key] as string; List <string> keyMethodItems = new List <string>(keyMethod.Split(',')); foreach (var methodItem in keyMethodItems) { List <KeyCode> outCodes = new List <KeyCode>(); var keyCodes = methodItem.Split('|'); foreach (var k in keyCodes) { // 文字列をKeyCodeに変換 if (k != "") { outCodes.Add((KeyCode)Enum.Parse(typeof(KeyCode), k)); } } if (outCodes.Count != 0) { outMethods.Add(outCodes); } } result.Add(key.ToLower(), outMethods); } return(result); }