I've had a go at creating a small class in C# that can generated salted hashes from text. I would like to know how this could be improved (in terms of code style) and whether or not this code is secure enough that it could be used in a professional environment (it won't be).
Hasher.cs
using System.Security.Cryptography;
namespace HashAndSaltTest
{
public static class Hasher
{
private static readonly int MaxSaltLength = 32;
public static byte[] GenerateSaltedHash(byte[] plainText)
{
HashAlgorithm algorithm = new SHA256Managed();
byte[] salt = GenerateSalt();
byte[] saltedText = new byte[plainText.Length + salt.Length];
for (int i = 0; i < plainText.Length; i++)
saltedText[i] = plainText[i];
for (int i = 0; i < salt.Length; i++)
saltedText[plainText.Length + i] = salt[i];
return algorithm.ComputeHash(saltedText);
}
private static byte[] GenerateSalt()
{
byte[] salt = new byte[MaxSaltLength];
using (RandomNumberGenerator random = new RNGCryptoServiceProvider())
random.GetNonZeroBytes(salt);
return salt;
}
}
}