private string SHA(string s, WG_Hash hash) { byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s); byte[] result; HashAlgorithm sha = null; switch(hash){ case WG_Hash.Sha1: sha = new SHA1Managed(); break; case WG_Hash.Sha256: sha = new SHA256Managed(); break; } result = sha.ComputeHash(bytes); return System.Convert.ToBase64String(result); }
private string SHA(string s, WG_Hash hash) { byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s); byte[] result; HashAlgorithm sha; switch(hash){ case WG_Hash.Sha1: sha = new SHA1Managed(); break; case WG_Hash.Sha256: sha = new SHA256Managed(); break; default: throw new ArgumentException("Unknown hash algorithm.", "hash"); } result = sha.ComputeHash(bytes); return System.Convert.ToBase64String(result); }
private string SHA(string s, WG_Hash hash) { byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s); byte[] result; HashAlgorithm sha; switch (hash) { case WG_Hash.Sha1: sha = new SHA1Managed(); break; case WG_Hash.Sha256: sha = new SHA256Managed(); break; } result = sha.ComputeHash(bytes); return(System.Convert.ToBase64String(result)); }
private string SHA(string s, WG_Hash hash) { byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s); byte[] result; // assign "sha" to avoid "error CS0165: Use of unassigned local variable 'sha'" HashAlgorithm sha = new SHA1Managed(); switch (hash) { case WG_Hash.Sha1: sha = new SHA1Managed(); break; case WG_Hash.Sha256: sha = new SHA256Managed(); break; } result = sha.ComputeHash(bytes); return(System.Convert.ToBase64String(result)); }