HashRaw() 공개 메소드

Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. The raw bytes of the password to be hashed The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. A byte array containing only the resulting hash
public HashRaw ( byte password, byte salt ) : byte[]
password byte
salt byte
리턴 byte[]
예제 #1
0
        private static void Run(PasswordHasher hasher, string pwd, string salt, bool rawOnly, bool encodedOnly)
        {
            try
            {
                if (rawOnly)
                {
                    Console.WriteLine(ToHex(hasher.HashRaw(pwd, salt)));
                    return;
                }

                if (encodedOnly)
                {
                    Console.WriteLine(hasher.Hash(pwd, salt));
                    return;
                }

                var    startTime = DateTime.Now;
                string encoded   = hasher.Hash(pwd, salt);
                var    stopTime  = DateTime.Now;

                HashMetadata metadata = PasswordHasher.ExtractMetadata(encoded);

                Console.WriteLine("Hash:\t\t" + ToHex(metadata.Hash));
                Console.WriteLine("Encoded:\t" + encoded);
                Console.WriteLine("{0:0.000} seconds", (stopTime - startTime).TotalSeconds);

                if (hasher.Verify(encoded, pwd))
                {
                    Console.WriteLine("Verification ok");
                }
                else
                {
                    throw new Argon2Exception("verifying", Argon2Error.VERIFY_MISMATCH);
                }
            }
            catch (Exception ex)
            {
                Fatal(ex.Message);
            }
        }
예제 #2
0
        private static void Run(PasswordHasher hasher, string pwd, string salt, bool rawOnly, bool encodedOnly)
        {
            try
            {
                if (rawOnly)
                {
                    Console.WriteLine(ToHex(hasher.HashRaw(pwd, salt)));
                    return;
                }

                if (encodedOnly)
                {
                    Console.WriteLine(hasher.Hash(pwd, salt));
                    return;
                }

                var startTime = DateTime.Now;
                string encoded = hasher.Hash(pwd, salt);
                var stopTime = DateTime.Now;
                
                HashMetadata metadata = PasswordHasher.ExtractMetadata(encoded);

                Console.WriteLine("Hash:\t\t" + ToHex(metadata.Hash));
                Console.WriteLine("Encoded:\t" + encoded);
                Console.WriteLine("{0:0.000} seconds", (stopTime - startTime).TotalSeconds);

                if(hasher.Verify(encoded, pwd))
                    Console.WriteLine("Verification ok");
                else
                    throw new Argon2Exception("verifying", Argon2Error.VERIFY_MISMATCH);
            }
            catch (Exception ex)
            {
                Fatal(ex.Message);
            }
        }