public override string ToINIValue() { GetPropertyInfos(); if (this.Properties.Count == 0) { return(string.Empty); } var result = new StringBuilder(); result.Append("("); var delimiter = ""; foreach (var prop in this.Properties.OrderBy(p => p.Name)) { result.Append(delimiter); var attr = prop.GetCustomAttributes(typeof(AggregateIniValueEntryAttribute), false).OfType <AggregateIniValueEntryAttribute>().FirstOrDefault(); var propName = string.IsNullOrWhiteSpace(attr?.Key) ? prop.Name : attr.Key; var val = prop.GetValue(this); var propValue = StringUtils.GetPropertyValue(val, prop); result.Append($"{propName}={propValue}"); delimiter = DELIMITER.ToString(); } result.Append(")"); return(result.ToString()); }
/// <summary> /// Password-Based Key Derivation Function 2 /// https://github.com/defuse/password-hashing /// </summary> public override void Execute() { Verified = false; if (Salt != null && !string.IsNullOrEmpty(HashAlgorithm)) { var passwordHash = GetHash( Login, Password, Salt, HashAlgorithm, Iterations, PasswordHashLength); Hash = string.Join(DELIMITER.ToString(), new string[] { HashAlgorithm, Iterations.ToString(), PasswordHashLength.ToString(), Convert.ToBase64String(Salt), Convert.ToBase64String(passwordHash) }); } else { Hash = null; } if (!string.IsNullOrEmpty(ToVerify) /*&& !string.IsNullOrEmpty(Login)*/ && !string.IsNullOrEmpty(Password)) { var split = ToVerify.Split(DELIMITER); var hash = Convert.FromBase64String(split[PASSWORD_HASH_INDEX]); var storedHashSize = Int32.Parse(split[PASSWORD_HASH_BYTES_INDEX]); if (storedHashSize == hash.Length) { var computedHash = GetHash( Login, Password, Convert.FromBase64String(split[SALT_INDEX]), split[HASH_ALGORITHM_INDEX], Int32.Parse(split[PBKDF2_ITERATIONS_INDEX]), hash.Length); Verified = SlowEquals(hash, computedHash); } } else { Verified = false; } }
private StringCollection GetShipToLocationCollection(string text) { StringCollection sc = new StringCollection(); string [] s = text.Split(DELIMITER.ToCharArray()); int len = s.Length; for (int i = 0; i < len; i++) { string code = GetShipToLocationCode(s[i]); if (code != null) { sc.Add(code); } } return(sc); }
public string ToIniValue(NPCSpawnContainerType containerType) { GetPropertyInfos(); if (this.Properties.Count == 0) { return(string.Empty); } var result = new StringBuilder(); var delimiter = ""; foreach (var prop in this.Properties) { var attrSpawn = prop.GetCustomAttributes(typeof(NPCSpawnAttribute), false).OfType <NPCSpawnAttribute>().FirstOrDefault(); if (!attrSpawn?.ContainerTypes?.Contains(containerType) ?? false) { continue; } result.Append(delimiter); var attr = prop.GetCustomAttributes(typeof(AggregateIniValueEntryAttribute), false).OfType <AggregateIniValueEntryAttribute>().FirstOrDefault(); var propName = string.IsNullOrWhiteSpace(attr?.Key) ? prop.Name : attr.Key; result.Append($"{propName}="); if (attr?.ValueWithinBrackets ?? false) { result.Append("("); } var val = prop.GetValue(this); var spawnCollection = val as ISpawnIniValuesCollection; if (spawnCollection != null) { var iniVals = spawnCollection.ToIniValues(containerType); var delimiter2 = ""; foreach (var iniVal in iniVals) { result.Append(delimiter2); if (attr?.ListValueWithinBrackets ?? false) { result.Append($"({iniVal})"); } else { result.Append(iniVal); } delimiter2 = DELIMITER.ToString(); } } else { var collection = val as IIniValuesCollection; if (collection != null) { var iniVals = collection.ToIniValues(); var delimiter2 = ""; foreach (var iniVal in iniVals) { result.Append(delimiter2); if (attr?.ListValueWithinBrackets ?? false) { result.Append($"({iniVal})"); } else { result.Append(iniVal); } delimiter2 = DELIMITER.ToString(); } } else { var propValue = StringUtils.GetPropertyValue(val, prop); result.Append(propValue); } } if (attr?.ValueWithinBrackets ?? false) { result.Append(")"); } delimiter = DELIMITER.ToString(); } return(result.ToString()); }