/// <summary> /// Encrypts the specified password using the specified hash algoritm /// </summary> /// <param name="passWord"></param> /// <param name="salt"></param> /// <param name="hashAlgoritm"></param> /// <returns></returns> public static string EncryptPassWord(string passWord, string salt, HashAlgoritm hashAlgoritm) { UTF8Encoding textConverter = new UTF8Encoding(); HashAlgorithm hash; switch (hashAlgoritm) { case HashAlgoritm.SHA1: hash = new SHA1Managed(); break; case HashAlgoritm.SHA256: hash = new SHA256Managed(); break; case HashAlgoritm.SHA384: hash = new SHA384Managed(); break; case HashAlgoritm.SHA512: hash = new SHA512Managed(); break; default: hash = new MD5CryptoServiceProvider(); break; } string tmpPassword = string.Format("{0}_{1}", passWord, salt); byte[] passBytes = textConverter.GetBytes(tmpPassword); return Convert.ToBase64String(hash.ComputeHash(passBytes)); }
/// <summary> /// Encrypts the specified password using the specified hash algoritm /// </summary> /// <param name="passWord"></param> /// <param name="hashAlgoritm"></param> /// <returns></returns> public static string EncryptPassWord(string passWord, HashAlgoritm hashAlgoritm) { return EncryptPassWord(passWord, string.Empty, hashAlgoritm); }