-4
 private void creatPassordHash(string password, out byte[] passwordHach, out byte[] passwordSalt)
        {
            using ( var hmac = System.Security.Cryptography.HMACSHA512()){
                passwordSalt = hmac.key;
                passwordHach = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
            }

i got this messege Non-invocable member 'HMACSHA512' cannot be used like a method

3
  • 3
    Use new keyword, because you're calling a constructor: var hmac = new System.Security.Cryptography.HMACSHA512(). Jan 30, 2019 at 6:54
  • 1
    Nobody never reads exception messages:( "Non-invocable member 'HMACSHA512' cannot be used like a method" means that System.Security.Cryptography.HMACSHA512 (spoiler: it's a class) is non-invocable member and you cannot use it like a method.
    – vasily.sib
    Jan 30, 2019 at 6:55
  • thanks Tetsuya Yamamoto it's work fine now. Thanks all
    – ooo3
    Jan 30, 2019 at 7:02

1 Answer 1

1

You're probably getting that error because you're not using the new keyword. Your code should look something like the following:

private void creatPassordHash(string password, out byte[] passwordHach, out byte[] passwordSalt)
{
    using (var hmac = new System.Security.Cryptography.HMACSHA512())
    {
        passwordSalt = hmac.key;
        passwordHach = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
    }
}

Hope it helps!

1
  • thanks dear it works fine
    – ooo3
    Jan 30, 2019 at 8:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.