public static string Sha256(string randomString) { string hash = String.Empty; byte[] crypto = new SHA256Managed().ComputeHash(Encoding.ASCII.GetBytes(randomString)); return(crypto.Aggregate(hash, (current, theByte) => current + theByte.ToString("x2"))); }
public static string hashPassword(string password) { var hash = string.Empty; var crypto = new SHA256Managed().ComputeHash(Encoding.ASCII.GetBytes(password), 0, Encoding.ASCII.GetByteCount(password)); return(crypto.Aggregate(hash, (current, theByte) => current + theByte.ToString("x2"))); }
public static string Sha256(params string[] data) { var hash = string.Empty; var crypto = new SHA256Managed().ComputeHash(Encoding.ASCII.GetBytes(string.Join("", data))); return(crypto.Aggregate(hash, (current, theByte) => current + theByte.ToString("x2"))); }
/// <summary> /// Convert string to sha256 hash /// </summary> /// <param name="data">string to convert</param> /// <returns>sha256 hash or null</returns> public static string ToSha256(this string data) { try { if (String.IsNullOrEmpty(data)) { return(null); } var hashValue = new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(data)); var hex = hashValue.Aggregate("", (current, x) => current + String.Format("{0:x2}", x)); if (String.IsNullOrEmpty(hex)) { throw new Exception("Erro creating SHA256 hash"); } return(hex); } catch (Exception e) { Debug.WriteLine(e); return(null); } }