Indien het gaat om het versleutelen van wachtwoorden, heb je hier wellicht wat aan. Als je meer informatie nodig hebt hoor ik het wel.
[CPP]
using System.Security.Cryptography;
public class Encryptie
{
public static string GenerateSalt(int size)
{
byte[] salt = new byte[size];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(salt);
return Convert.ToBase64String(salt);
}
public static string GenerateSalt()
{
return GenerateSalt(8);
}
public static string CreatePasswordHash(string password, string salt)
{
byte[] passBytes = Encoding.UTF8.GetBytes(password);
byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
byte[] passWithSaltBytes = new byte[passBytes.Length + saltBytes.Length];
// Copy plain text bytes into resulting array.
for (int i = 0; i < passBytes.Length; i++)
passWithSaltBytes = passBytes;
// Append salt bytes to the resulting array.
for (int i = 0; i < saltBytes.Length; i++)
passWithSaltBytes[passBytes.Length + i] = saltBytes;
HashAlgorithm hashAlgorithm = new SHA256Managed();
// Compute hash value of our plain text with appended salt.
byte[] passwordHash = hashAlgorithm.ComputeHash(passWithSaltBytes);
return Convert.ToBase64String(passwordHash);
}
}[/CPP]