public static byte[] GetBytes(byte[] Bytes, Algorithm Algorithm = Algorithm.MD5, byte[] SaltBytes = null, int SaltLength = 16, int DerivedKeyLength = 128) { if (SaltBytes == null) { SaltBytes = new byte[SaltLength]; new RNGCryptoServiceProvider().GetNonZeroBytes(SaltBytes); } switch (Algorithm) { case Algorithm.PBKDF2: { var hash = new Rfc2898DeriveBytes(Bytes, SaltBytes, 20000); return hash.GetBytes(DerivedKeyLength); } default: { HashAlgorithm hash = GetHashAlgorithm(Algorithm); byte[] hashBytes = hash.ComputeHash(Bytes.Append(SaltBytes).ToArray()); return hashBytes.Append(SaltBytes).ToArray(); } } }