📜  在 web app .net 中加密密码最简单的方法 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:52.946000             🧑  作者: Mango

代码示例1
public static string HashPassword(string password, string algorithm = "sha256")
{
   return Hash(Encoding.UTF8.GetBytes(password), algorithm);
}

private static string Hash(byte[] input, string algorithm = "sha256")
{
    using (var hashAlgorithm = HashAlgorithm.Create(algorithm))
    {
        return Convert.ToBase64String(hashAlgorithm.ComputeHash(input));
    }
}