Ejemplo n.º 1
0
        public void TestDataHasherWithAlternativeName()
        {
            IDataHasher hasher = CryptoTestFactory.CreateDataHasher(HashAlgorithm.GetByName("sha-2"));

            byte[] data = System.Text.Encoding.UTF8.GetBytes(Resources.DataHasher_TestString);
            hasher.AddData(data);
            Assert.AreEqual(HashAlgorithm.Sha2256.Length, hasher.GetHash().Value.Length, "Hash length should be correct");
            byte[] bytes = new byte[hasher.GetHash().Value.Length];
            hasher.GetHash().Value.CopyTo(bytes, 0);
            Assert.AreEqual("CF-00-FC-3A-72-A2-F7-1C-7D-E2-B7-18-C0-A4-DF-F3-8D-83-C0-E1-95-7E-C2-19-C3-B2-66-F8-CC-38-B9-EA", BitConverter.ToString(bytes),
                            "Hash value should be calculated correctly");
        }
Ejemplo n.º 2
0
        public static HashAlgorithm GetHashAlgorithm(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(HashAlgorithm.Default);
            }

            HashAlgorithm algorithm = HashAlgorithm.GetByName(name);

            if (algorithm == null)
            {
                throw new Exception("Invalid hmac algorithm name value in config. Name: " + name);
            }

            return(algorithm);
        }
Ejemplo n.º 3
0
        public void TestAlgorithmGetByIdWithInvalidName()
        {
            HashAlgorithm algorithm = HashAlgorithm.GetByName("TEST");

            Assert.IsNull(algorithm, "Algorithm should not be found with given name");
        }