Help whit Pbkdf2 in C#

I trying to make a pbkdf2 whit C# but got error.

Using:

using System;
using System.Security.Cryptography;
using System.Text;
BLOCK:ConstantString
  value = @input.PASS
  => VAR @passw
ENDBLOCK

class Program
{
    static string passw = @passw;

    static void Main()
    {
        string passw = GetPasswordFromGlobalInput();

        
        if (string.IsNullOrEmpty(passw))
        {
            Console.WriteLine("La contraseña no puede estar vacía.");
            return;
        }

        string hash = HashPassword(passw);
        
        Console.WriteLine(hash);
    }

    private static string GetPasswordFromGlobalInput()
    {

        return passw;
    }

    public static string HashPassword(string password)
    {

        int iterations = 10000;
        int saltSize = 16;
        int hashSize = 32;


        byte[] salt = new byte[saltSize];
        using (var rng = new RNGCryptoServiceProvider())
        {
            rng.GetBytes(salt);
        }


        var pbkdf2 = new Rfc2898DeriveBytes(password, salt, iterations, HashAlgorithmName.SHA256);
        byte[] hash = pbkdf2.GetBytes(hashSize);


        byte[] hashBytes = new byte[saltSize + hashSize];
        Array.Copy(salt, 0, hashBytes, 0, saltSize);
        Array.Copy(hash, 0, hashBytes, saltSize, hashSize);


        string base64Hash = Convert.ToBase64String(hashBytes);

        return base64Hash;
    }
}

CLOG BallBlue @base64Hash

NAMESPACE

System.Security.Cryptography

CODE

string passw = input.PASS;
string base64Hash = string.Empty;

if (string.IsNullOrEmpty(passw))
{
    
    data.Logger.LogObject("La contraseña no puede estar vacía.");
}
else
{
    int iterations = 10000;
    int saltSize = 16;
    int hashSize = 32;

    byte[] salt = new byte[saltSize];
    using (var rng = new RNGCryptoServiceProvider())
    {
        rng.GetBytes(salt);
    }

    var pbkdf2 = new Rfc2898DeriveBytes(passw, salt, iterations, HashAlgorithmName.SHA256);
    byte[] hash = pbkdf2.GetBytes(hashSize);

    byte[] hashBytes = new byte[saltSize + hashSize];
    Array.Copy(salt, 0, hashBytes, 0, saltSize);
    Array.Copy(hash, 0, hashBytes, saltSize, hashSize);

    base64Hash = Convert.ToBase64String(hashBytes);
}
1 Like

thanks for guide me.