public CacheItem(ComparableBytesAbstract DesiredLookupKey, IHashable CacheValue, TimeSpan ExpireIn) { Key = DesiredLookupKey.Bytes; Value = CacheValue; ExpireDate = DateTime.Now.Add(ExpireIn); AddedDate = DateTime.Now; }
public string Calculate(IHashable hashable) { var hashCode = hashable.GetHashCode(); var md5 = hashCode.ToString().ToMd5(); return(md5); }
private static Object_AST evalHashLiteral(HashLiteral hash, Environment_AST env) { Dictionary <HashKey, HashPair> pairs = new Dictionary <HashKey, HashPair>(); foreach (var item in hash.Pairs) { Object_AST key = Eval(item.Key, env); if (key is Error_AST) //for recursive Eval calls, check the returned result of the recursive Eval. If an error, return rightaway. Otherwise we will get a { return(key); //higher level error obscuring the true source of error } IHashable hashKey = key as IHashable; if (hashKey is null) { return(new Error_AST(string.Format("unusable as hash key: {0}", key.Type))); } Object_AST val = Eval(item.Value, env); if (val is Error_AST) //for recursive Eval calls, check the returned result of the recursive Eval. If an error, return rightaway. Otherwise we will get a { return(val); //higher level error obscuring the true source of error } HashKey hashed = hashKey.HashKey(); pairs[hashed] = new HashPair { Key = key, Value = val }; } return(new Hash_AST { Pairs = pairs }); }
/// <summary> /// Получить хеш. /// </summary> /// <param name="data">Хешируемый компонент.</param> /// <returns>Хеш компонента.</returns> public string GetHash(IHashable data) { var dataBeforeHash = data.GetStringForHash(); var hash = GetHash(dataBeforeHash); return(hash); }
public static byte[] CalculateSHA256(IHashable hashable) { MemoryStream ms = hashable.GetHashable(); byte[] hash = sha256.ComputeHash(ms.ToArray()); ms.Dispose(); return(hash); }
/// <summary> /// Получить хеш компонента. /// </summary> /// <param name="component">Компонент, поддерживающий хеширование.</param> /// <param name="algorithm">Алгоритм хеширования.</param> /// <returns>Хеш компонента.</returns> public static string GetHash(this IHashable component, IAlgorithm algorithm) { Contract.Requires <ArgumentNullException>(component != null, "Не возможно выполнить хеширование. Аргумент равен null."); Contract.Ensures(!string.IsNullOrEmpty(Contract.Result <string>())); var hash = algorithm.GetHash(component); return(hash); }
/// <summary> /// Computes the Hash of the given <see cref="IHashable"/> input. /// </summary> /// <typeparam name="H">The <see cref="HashAlgorithm"/> to use.</typeparam> /// <param name="input">The <see cref="IHashable"/> to compute the hash of.</param> /// <param name="hashingOptions">The options to use to compte the Hash.</param> /// <returns></returns> public static HashResult <H> Hash <H>(this IHashable input, HashingOptions hashingOptions = null) where H : HashAlgorithm, new() { if (input == null) { throw new ArgumentNullException(nameof(input)); } return(new HashResult <H>(input, hashingOptions)); }
public SoftFile(int id, string name, string thumbnailpath, string[] tags, IHashable i) { Name = name; Id = id; ThumbnailPath = thumbnailpath ?? ""; _tags = new List <string>(tags ?? new string[0]); _references = new List <SoftFile>(); SHA256 = i.SHA256; }
/// <summary> /// Получить хеш. /// </summary> /// <param name="data">Хешируемый компонент.</param> /// <returns>Хеш компонента.</returns> public string GetHash(IHashable data) { Contract.Requires <ArgumentNullException>(data != null, $"Не возможно выполнить хеширование. Аргумент {nameof(data)} равен null."); Contract.Ensures(!string.IsNullOrEmpty(Contract.Result <string>())); var dataBeforeHash = data.GetStringForHash(); var hash = GetHash(dataBeforeHash); return(hash); }
public static string GetJson(this IHashable component) { var jsonFormatter = new DataContractJsonSerializer(component.GetType()); using (var ms = new MemoryStream()) { jsonFormatter.WriteObject(ms, component); var jsonString = Encoding.UTF8.GetString((ms.ToArray())); return(jsonString); } }
public static bool IsCorrect(this IHashable component, IAlgorithm algorithm = null) { if (algorithm == null) { algorithm = AlgorithmHelper.GetDefaultAlgorithm(); } var correct = component.Hash == component.GetHash(algorithm); return(correct); }
public static string GetHash(this IHashable component, IAlgorithm algorithm = null) { if (algorithm == null) { algorithm = GetDefaultAlgorithm(); } var hash = algorithm.GetHash(component); return(hash); }
/// <summary> /// Получить хеш компонента. /// </summary> /// <param name="component">Компонент, поддерживающий хеширование.</param> /// <param name="algorithm">Алгоритм хеширования.</param> /// <returns>Хеш компонента.</returns> public static string GetHash(this IHashable component, IAlgorithm algorithm = null) { // Если не был передан алгоритм хеширования, то получаем алгоритм по умолчанию. if (algorithm == null) { algorithm = GetDefaultAlgorithm(); } var hash = algorithm.GetHash(component); return(hash); }
/// <summary> /// Create an <see cref="HashResult{H}"/> /// </summary> /// <param name="input">the object from which the hash is to be calculated.</param> /// <param name="hashingOptions">Optional. Options to change the behaviour of the <see cref="HashResult{H}"/>.</param> public HashResult(IHashable input, HashingOptions hashingOptions = null) { #region HashingOptions Management if (hashingOptions is null) { hashingOptions = HashingOptions.DefaultHashingOptions; } #endregion LazyHash = new Lazy <byte[]>(() => input.GetBytesForHash().Hash <H>()); LazyStringValue = new Lazy <string>(() => ToString(HashingOptions.Separator, HashingOptions.Format), true); }
public static PressureDropITem Parse(string s, IHashable hashable, IFormatProvider formatProvider) { var dValue = double.TryParse(s, out double r); var unit = hashable.GetHashableUnit(OwnerUnitPropertyName); if (string.IsNullOrWhiteSpace(unit)) { unit = hashable.GetHashableUnit("Water" + OwnerUnitPropertyName); } if (dValue) { if (!string.IsNullOrWhiteSpace(unit)) { return(PressureDropITem.Factory.Create(r, unit)); } else { return(PressureDropITem.Factory.Create(r, U.kPa)); } } else { Regex regex = new Regex(@"\d+"); Match match = regex.Match(s); var isNumber = double.TryParse(match.Value, out double v); if (isNumber) { if (!string.IsNullOrWhiteSpace(unit)) { return(PressureDropITem.Factory.Create(v, unit)); } else { return(PressureDropITem.Factory.Create(v, U.kPa)); } } if (!string.IsNullOrWhiteSpace(unit)) { return(PressureDropITem.Factory.Create(0, unit)); } else { return(PressureDropITem.Factory.Create(0, U.kPa)); } } }
public bool Compare(IHashable h) { if (h == null || SHA256 == null) { return(false); } if (h.SHA256.Compare(SHA256)) { return(true); } else { return(false); } }
/// <summary> /// Calculates the hash code of this object. /// </summary> public static int CalculateHash(this IHashable context) { unchecked { int hash = 486187739; foreach (var param in context.GetHashParams()) { if (param != null) { hash = (hash * 16777619) ^ param.GetHashCode(); } } return(context.HashCode = hash); } }
public int Calculate(IHashable hashable) { var hash = 0; if (hashable == null) return hash; if (_hashCache.TryGetValue(hashable, out hash) == false) { hash = hashable.CalculateHash(this); _hashCache.Add(hashable, hash); } return hash; }
public void Hash(IHashable input) { var builder = new StringBuilder(); using (var hash = SHA256.Create()) { byte[] result = hash.ComputeHash(input.GetHashData()); foreach (byte b in result) { builder.Append(b.ToString("x2")); } } input.Hash = builder.ToString(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IUserRepository users, IAuthenticationRegisterService registration, IHashable hashManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseStaticFiles(); app.UseDefaultFiles(); app.UseAuthentication(); app.UseFileServer(); app.UseSignalR(route => route.MapHub <NotificationHub>("/notification")); var supportedCulture = new[] { new CultureInfo("en"), new CultureInfo("ru") }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("en"), SupportedCultures = supportedCulture, SupportedUICultures = supportedCulture }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); if (users.GetByName("Admin") == null) { registration.CreateNewUser("Admin", "*****@*****.**", "Admin", hashManager, "Admin"); } }
public int Calculate(IHashable hashable) { var hash = 0; if (hashable == null) { return(hash); } if (_hashCache.TryGetValue(hashable, out hash) == false) { hash = hashable.CalculateHash(this); _hashCache.Add(hashable, hash); } return(hash); }
public static AirFlowItem Parse(string s, IHashable hashable, IFormatProvider formatProvider) { var dValue = double.TryParse(s, out double r); var unit = hashable.GetHashableUnit("AirFlowUnit"); if (dValue) { if (!string.IsNullOrWhiteSpace(unit)) { return(AirFlowItem.Factory.Create(r, unit)); } else { return(AirFlowItem.Factory.Create(r, U.LpS)); } } else { Regex regex = new Regex(@"\d+"); Match match = regex.Match(s); var isNumber = double.TryParse(match.Value, out double v); if (isNumber) { if (!string.IsNullOrWhiteSpace(unit)) { return(AirFlowItem.Factory.Create(v, unit)); } else { return(AirFlowItem.Factory.Create(v, U.LpS)); } } if (!string.IsNullOrWhiteSpace(unit)) { return(AirFlowItem.Factory.Create(0, unit)); } else { return(AirFlowItem.Factory.Create(0, U.LpS)); } } }
public static PipeSizeItem Parse(string s, IHashable hashable, IFormatProvider formatProvider) { var dValue = PipeSizeTableItem.AllData.Where(xi => xi.ValueInMM == s || xi.ValueInInch == s).FirstOrDefault(); if (dValue != null) { var ss_value = PipeSizeTableItem.AllData.Where(xi => xi.ValueInMM == s).FirstOrDefault(); if (ss_value != null) { return(Factory.Create(ss_value.ValueInMM, U.mm)); } else { return(Factory.Create(ss_value.ValueInInch, U.inch)); } } else { Regex regex = new Regex(@"\d+"); Match match = regex.Match(s); var isNumber = double.TryParse(match.Value, out double v); if (isNumber) { var unit = hashable.GetHashableUnit(OwnerUnitPropertyName); if (!string.IsNullOrWhiteSpace(unit)) { return(PipeSizeItem.Factory.Create(s, unit)); } else { return(PipeSizeItem.Factory.Create(s, U.mm)); } } return(Factory.Create(PipeSizeTableItem.AllData.First().ValueInMM, U.mm)); } }
/// <summary> /// Compute the <see cref="SHA256"/> Hash with of the given <see cref="IHashable"/>. /// </summary> /// <param name="input">The <see cref="IHashable"/> to calculate the hash of.</param> /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param> /// <returns></returns> public static HashResult <SHA256CryptoServiceProvider> Sha256(this IHashable input, HashingOptions hashingOptions = null) => input.Hash <SHA256CryptoServiceProvider>(hashingOptions);
public string Calculate(IHashable hashable) { var json = JsonConvert.SerializeObject(hashable, Newtonsoft.Json.Formatting.None); return(json.ToMd5()); }
/// <summary> /// Compute the <see cref="System.Security.Cryptography.MD5"/> Hash with of the given <see cref="IHashable"/>. /// </summary> /// <param name="input">The <see cref="IHashable"/> to calculate the hash of.</param> /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param> /// <returns></returns> public static HashResult <MD5CryptoServiceProvider> MD5(this IHashable input, HashingOptions hashingOptions = null) => input.Hash <MD5CryptoServiceProvider>(hashingOptions);
public AccountController(IUserRepository users, IHashable hashManager, IAuthenticationRegisterService usersManager) { this.users = users; this.hashManager = hashManager; this.usersManager = usersManager; }
public static void Process(IHashable hashable) => hashable.Hash();
public bool Equals(IHashable i) { return(Compare(i)); }
public bool IsValid(IHashable hashable) { var hash = GetHash(hashable.Password, hashable.Salt); return hash == hashable.Hash; }
public IHashable Hash(IHashable hashable) { hashable.Salt = Guid.NewGuid().ToString(); hashable.Hash = GetHash(hashable.Password, hashable.Salt); return hashable; }
string IAlgorithm.GetHash(IHashable data) { Contract.Requires <ArgumentNullException>(data != null, $"Hashing was not possible. Argument {nameof(data)} is null."); Contract.Ensures(!string.IsNullOrEmpty(Contract.Result <string>())); return(string.Empty); }
public bool Exists(IHashable i) { return(_softFiles.Exists(n => n.Compare(i))); }