نوشته شده توسط
shahrabiamir
با سلام
برای hash password در سی شارپ از کدوم کلاس باید استفاده کرد؟
System.Security.Cryptography.SHA256Managed این کلاس برای hash کردن رمز عبور است . برای استفاده از این کلاس، میتوانید به صورت زیر عمل کنید .
using System.Security.Cryptography;
using System.Text;
public static string HashPassword(string password)
{
using (SHA256 sha256Hash = SHA256.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(pass word));
// Convert the byte array to a string and return it.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}