Hashing a string with Sha256

前端 未结 7 2067
一向
一向 2020-12-02 04:31

I try to hash a string using SHA256, I\'m using the following code:

using System;
using System.Security.Cryptography;
using System.Text;
 public class Hash
          


        
7条回答
  •  抹茶落季
    2020-12-02 04:52

    public string EncryptPassword(string password, string saltorusername)
            {
                using (var sha256 = SHA256.Create())
                {
                    var saltedPassword = string.Format("{0}{1}", salt, password);
                    byte[] saltedPasswordAsBytes = Encoding.UTF8.GetBytes(saltedPassword);
                    return Convert.ToBase64String(sha256.ComputeHash(saltedPasswordAsBytes));
                }
            }
    

提交回复
热议问题