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