Esempio n. 1
0
        public void ModifyKeyAfterCompute()
        {
            // Rfc2202_7
            var key          = ByteExtensions.Repeat(0xaa, 80);
            var data         = ByteExtensions.HexToByteArray("54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461"); // "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
            var expectedHash = ByteExtensions.HexToByteArray("6f630fad67cda0ee1fb1f562db3aa53e");
            var hmac         = CreateHMACMD5(key);

            var actualHash = hmac.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);

            // Rfc2202_2: assign key smaller than block size
            key          = ByteExtensions.HexToByteArray("4a656665");                                                 // "Jefe";
            data         = ByteExtensions.HexToByteArray("7768617420646f2079612077616e7420666f72206e6f7468696e673f"); // "what do ya want for nothing?"
            expectedHash = ByteExtensions.HexToByteArray("750c783e6ab0b503eaa86e310a5db738");
            hmac.Key     = key;

            actualHash = hmac.ComputeHash(data);
            Assert.Equal(expectedHash, actualHash);

            // Rfc2202_7: assign key larger than block size
            key          = ByteExtensions.Repeat(0xaa, 80);
            data         = ByteExtensions.HexToByteArray("54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461"); // "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
            expectedHash = ByteExtensions.HexToByteArray("6f630fad67cda0ee1fb1f562db3aa53e");
            hmac.Key     = key;

            actualHash = hmac.ComputeHash(data);
            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 2
0
        public void test_7()
        {
            var data         = ByteExtensions.HexToByteArray("4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839"); // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
            var expectedHash = ByteExtensions.HexToByteArray("b0e20b6e3116640286ed3a87a5713079b21f5189");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 3
0
        public void test_6()
        {
            var data         = ByteExtensions.HexToByteArray("6162636462636465636465666465666765666768666768696768696a68696a6b696a6b6c6a6b6c6d6b6c6d6e6c6d6e6f6d6e6f706e6f7071"); // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
            var expectedHash = ByteExtensions.HexToByteArray("12a053384a9c0c88e405a06c27dcf49ada62eb2b");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 4
0
        public void test_5()
        {
            var data         = ByteExtensions.HexToByteArray("6162636465666768696a6b6c6d6e6f707172737475767778797a"); // "abcdefghijklmnopqrstuvwxyz"
            var expectedHash = ByteExtensions.HexToByteArray("f71c27109c692c1b56bbdceb5b9d2865b3708dbc");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 5
0
        public void test_4()
        {
            var data         = ByteExtensions.HexToByteArray("6d65737361676520646967657374"); // "message digest"
            var expectedHash = ByteExtensions.HexToByteArray("5d0689ef49d2fae572b881b123a85ffa21595f36");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 6
0
        public void test_3()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 7
0
        public void test_2()
        {
            var data         = ByteExtensions.HexToByteArray("61"); // "a"
            var expectedHash = ByteExtensions.HexToByteArray("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 8
0
        public void test_1()
        {
            var data         = new byte[0]; // ""
            var expectedHash = ByteExtensions.HexToByteArray("9c1185a5c5e9fc54612808977ee8f548b2258d31");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 9
0
        public void test_9()
        {
            var data         = ByteExtensions.Repeat(0x61, 1000000);
            var expectedHash = ByteExtensions.HexToByteArray("52783243c1697bdbe16d37f97f68f08325dc1528");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 10
0
        public void NistShaAll_2()
        {
            var data         = ByteExtensions.HexToByteArray("61626364656667686263646566676869636465666768696a6465666768696a6b65666768696a6b6c666768696a6b6c6d6768696a6b6c6d6e68696a6b6c6d6e6f696a6b6c6d6e6f706a6b6c6d6e6f70716b6c6d6e6f7071726c6d6e6f707172736d6e6f70717273746e6f707172737475"); // "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
            var expectedHash = ByteExtensions.HexToByteArray("09330C33F71147E83D192FC782CD1B4753111B173B3B05D22FA08086E3B0F712FCC7C71A557E2DB966C3E9FA91746039");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 11
0
        public void NistShaAll_1()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 12
0
        public void Fips180_3()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("61", 1000000)); // "a" * 1000000
            var expectedHash = ByteExtensions.HexToByteArray("e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 13
0
        public void test_8()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("31323334353637383930", 8)); // "1234567890" x 8
            var expectedHash = ByteExtensions.HexToByteArray("9b752e45573d4b39f4dbd3323cab82bf63326bfb");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 14
0
        public void Rfc1321_1()
        {
            var data         = new byte[0]; // ""
            var expectedHash = ByteExtensions.HexToByteArray("d41d8cd98f00b204e9800998ecf8427e");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 15
0
        public void Fips180_1()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 16
0
        public void Fips180_2()
        {
            var data         = ByteExtensions.HexToByteArray("6162636462636465636465666465666765666768666768696768696a68696a6b696a6b6c6a6b6c6d6b6c6d6e6c6d6e6f6d6e6f706e6f7071"); // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
            var expectedHash = ByteExtensions.HexToByteArray("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 17
0
        public void Fips180_3()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("61", 1000000)); // "a" * 1000000
            var expectedHash = ByteExtensions.HexToByteArray("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 18
0
        public void Rfc3174_4()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("3031323334353637", 8 * 10)); // "01234567" * (8*10)
            var expectedHash = ByteExtensions.HexToByteArray("DEA356A2CDDD90C7A7ECEDC5EBB563934F460452");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 19
0
        public void Fips180_1()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 20
0
        public void Rfc3174_2()
        {
            var data         = ByteExtensions.HexToByteArray("6162636462636465636465666465666765666768666768696768696a68696a6b696a6b6c6a6b6c6d6b6c6d6e6c6d6e6f6d6e6f706e6f7071"); // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
            var expectedHash = ByteExtensions.HexToByteArray("84983E441C3BD26EBAAE4AA1F95129E5E54670F1");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 21
0
        public void Rfc3174_3()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("61", 1000000)); // "a" * 1000000
            var expectedHash = ByteExtensions.HexToByteArray("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 22
0
        public void Rfc1321_7()
        {
            var data         = ByteExtensions.HexToByteArray(StringExtensions.Repeat("31323334353637383930", 8)); // "1234567890" * 8
            var expectedHash = ByteExtensions.HexToByteArray("57edf4a22be3c955ac49da2e2107b67a");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 23
0
        public void Rfc3174_1()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("A9993E364706816ABA3E25717850C26C9CD0D89D");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 24
0
        public void Rfc1321_5()
        {
            var data         = ByteExtensions.HexToByteArray("6162636465666768696a6b6c6d6e6f707172737475767778797a"); // "abcdefghijklmnopqrstuvwxyz"
            var expectedHash = ByteExtensions.HexToByteArray("c3fcd3d76192e4007dfb496cca67e13b");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 25
0
        public void Rfc1321_6()
        {
            var data         = ByteExtensions.HexToByteArray("4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839"); // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
            var expectedHash = ByteExtensions.HexToByteArray("d174ab98d277d9f5a5611c2c9f419d9f");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 26
0
        public void Rfc1321_4()
        {
            var data         = ByteExtensions.HexToByteArray("6d65737361676520646967657374"); // "message digest"
            var expectedHash = ByteExtensions.HexToByteArray("f96b697d7cb7938d525a2f31aaf161d0");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 27
0
        public void Rfc1321_3()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("900150983cd24fb0d6963f7d28e17f72");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 28
0
        public void Rfc1321_2()
        {
            var data         = ByteExtensions.HexToByteArray("61"); // "a"
            var expectedHash = ByteExtensions.HexToByteArray("0cc175b9c0f1b6a831c399e269772661");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Esempio n. 29
0
        public void Fips180_2()
        {
            var data         = ByteExtensions.HexToByteArray("61626364656667686263646566676869636465666768696a6465666768696a6b65666768696a6b6c666768696a6b6c6d6768696a6b6c6d6e68696a6b6c6d6e6f696a6b6c6d6e6f706a6b6c6d6e6f70716b6c6d6e6f7071726c6d6e6f707172736d6e6f70717273746e6f707172737475"); // "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
            var expectedHash = ByteExtensions.HexToByteArray("8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
        public void When_HexToByteArray()
        {
            string source = "00FF";

            byte[] expected = new byte[] { 0, 255 };
            byte[] actual;
            actual = ByteExtensions.HexToByteArray(source);

            CollectionAssert.AreEqual(expected, actual);
        }