Search code examples
c#.netcryptographylibsodiumargon

Mechanism for verifying binary hash


I have a binary hash:

var hash = PasswordHash.ArgonHashBinary(Encoding.ASCII.GetBytes(passwd), salt,StrengthArgon.Interactive)

Please tell me how can I convert byte array returned by method ArgonHashBinary() so that I can verify my password using ArgonHashStringVerify().

P.S. there is no method that would allow me to verify password directly from binary hash i.e. there is no ArgonHashBinaryVerify() method.

Contrived example code:

var salt = PasswordHash.ArgonGenerateSalt();
var passwd = "ABCD";
var hash = PasswordHash.ArgonHashBinary(Encoding.ASCII.GetBytes(passwd), salt,StrengthArgon.Interactive);

if (ArgonHashStringVerify(hash, passwd))
{
    // password match
}
else 
{
    // error
}

Solution

  • You pair ArgonHashString() with ArgonHashStringVerify(), like in the examples in the unit test:

    const string PASSWORD = "gkahjfkjewrykjKJHKJHKJbhuiqyr  8923fhsjfkajwehkjg";
    var hash = PasswordHash.ArgonHashString(PASSWORD);
    
    Assert.IsTrue(PasswordHash.ArgonHashStringVerify(hash, PASSWORD));
    

    Note that ArgonHashBinary() has another use: you use it to generate from a (potentially weak) password a (strong) encryption key that you'll use to encrypt something (a file for example). So it isn't used for password checking.