コード例 #1
0
        public void HashManager_HMACSHA512_Hash_RandomKey()
        {
            for (var i = 0; i < _TestRandomRound; i++)
            {
                var randomValue       = Generator.RandomString();
                var key               = HashManager.GenerateHashedKey(Generator.RandomInt(1, 128));
                var hashedRandomValue = HashManager.HmacSha512.Hash(randomValue, ref key);

                string expectedHashed;
                using (var crypto = HMAC.Create("HMACSHA512"))
                {
                    crypto.Key = key;
                    var hashed = crypto.ComputeHash(Encoding.UTF8.GetBytes(randomValue));
                    expectedHashed = BitConverter.ToString(hashed)
                                     .Replace("-", string.Empty);
                }

                Assert.Equal(hashedRandomValue, expectedHashed);
            }
        }