Esempio n. 1
0
        public void ComputeAndVerifyHash_String_without_associated_data()
        {
            var verifyResult = new Argon2idHashResult();
            var errorMessage = "";

            var testStringBytes     = System.Text.Encoding.UTF8.GetBytes(_testString);
            var iterations          = 4;
            var kbMemorySize        = 1024;
            var degreeOfParallelism = 0; // auto-generate based on number of the processor's cores
            var amountBytesToReturn = 16;

            byte[] salt           = null; // auto-generate
            byte[] associatedData = null;
            byte[] knownSecret    = null;

            var hashResult = _argon2id.ComputeHash(testStringBytes, iterations, kbMemorySize, degreeOfParallelism, amountBytesToReturn, salt,
                                                   associatedData, knownSecret);

            if (hashResult.Success)
            {
                verifyResult = _argon2id.VerifyHash(hashResult.HashBytes, testStringBytes, iterations, kbMemorySize, degreeOfParallelism,
                                                    amountBytesToReturn, hashResult.SaltBytes, associatedData, knownSecret);

                if (!verifyResult.Success)
                {
                    errorMessage = verifyResult.Message;
                }
            }
            else
            {
                errorMessage = hashResult.Message;
            }

            Assert.IsTrue((hashResult.Success && verifyResult.Success), errorMessage);
        }