The password in the database is stored as a string. There is a method for password hashing

public string Hash(string password) { byte[] data = Encoding.Default.GetBytes(password); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] result = sha.ComputeHash(data); password = Encoding.Default.GetString(result); return password; } 

As a result of the execution of the code, "hieroglyphs" and incomprehensible signs are displayed in the string. How to fix it? What encoding to apply?

  • one
    You have a sequence of any bytes - respectively, can be any characters. Previously used heh representation. Now base64 is more common. In some cases, you can in binary form (system registry) - nick_n_a
  • one
    password=Convert.ToBase64String(result) - nick_n_a

1 answer 1

 public string Hash(string password) { byte[] data = Encoding.Default.GetBytes(password); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] result = sha.ComputeHash(data); password=Convert.ToBase64String(result); return password; }