Geeks With Blogs
.Nettuce Code Salad June 2012 Entries
Salt and hash a password in .NET
I endeavoured to follow the CrackStation rules: Salted Password Hashing - Doing it Right public class SaltedHash { public string Hash { get; private set; } public string Salt { get; private set; } public SaltedHash(string password) { var saltBytes = new byte[32]; using (var provider = new RNGCryptoServiceProvider()) provider.GetNonZeroBytes(sa... Salt = Convert.ToBase64String(salt... Hash = ComputeHash(Salt, password); } static string ComputeHash(string salt, string password) { var saltBytes ......

Posted On Thursday, June 14, 2012 8:22 PM

Serialize plain clean XML in .NET
public static string ToXml<T>(this T obj) where T : class { using (var stringWriter = new StringWriter()) { var xmlWriterSettings = new XmlWriterSettings { OmitXmlDeclaration = true }; using (var xmlWriter = XmlWriter.Create(stringWriter, xmlWriterSettings)) { var xmlSerializerNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); var xmlSerializer = new XmlSerializer(typeof(T)); xmlSerializer.Serialize(xml... obj, xmlSerializerNamespaces); } return stringWriter.ToString(); ......

Posted On Tuesday, June 12, 2012 4:40 PM

Convert Dynamic to Type and convert Type to Dynamic
public static class DynamicExtensions { public static T FromDynamic<T>(this IDictionary<string, object> dictionary) { var bindings = new List<MemberBinding>(); foreach (var sourceProperty in typeof(T).GetProperties().W... => x.CanWrite)) { var key = dictionary.Keys.SingleOrDef... => x.Equals(sourceProperty.Name, StringComparison.OrdinalIgn... if (string.IsNullOrEmpty(key)) continue; var propertyValue = dictionary[key]; bindings.Add(Expression.Bin... ......

Posted On Saturday, June 2, 2012 8:10 PM

Copyright © Jon Canning | Powered by: GeeksWithBlogs.net