Crypto.cs 739 B

1234567891011121314151617181920212223242526
  1. using System.Security.Cryptography;
  2. using System.Text;
  3. namespace Server.Utils
  4. {
  5. class Crypto
  6. {
  7. public const int SaltSize = 24;
  8. public const int HashSize = 24;
  9. public const int Iterations = 50;
  10. public static byte[] GenerateSalt()
  11. {
  12. var rng = RandomNumberGenerator.Create();
  13. byte[] salt = new byte[SaltSize];
  14. rng.GetBytes(salt);
  15. return salt;
  16. }
  17. public static string HashPassword(string password, byte[] salt)
  18. {
  19. Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations, HashAlgorithmName.SHA1);
  20. return Encoding.UTF8.GetString(pbkdf2.GetBytes(HashSize));
  21. }
  22. }
  23. }