public void TestHmacFromSimpleFile()
        {
            V1Hmac     expectedHmac = new V1Hmac(new byte[] { 0xF9, 0xAF, 0x2E, 0x67, 0x7D, 0xCF, 0xC9, 0xFE, 0x06, 0x4B, 0x39, 0x08, 0xE7, 0x5A, 0x87, 0x81 });
            Passphrase passphrase   = new Passphrase("a");

            using (V1AxCryptDocument document = new V1AxCryptDocument())
            {
                bool keyIsOk = document.Load(passphrase, new V1Aes128CryptoFactory().CryptoId, FakeDataStore.ExpandableMemoryStream(Resources.helloworld_key_a_txt));
                Assert.That(keyIsOk, Is.True, "The passphrase provided is correct!");
                Hmac hmac = document.DocumentHeaders.Headers.Hmac;
                Assert.That(hmac.GetBytes(), Is.EqualTo(expectedHmac.GetBytes()), "Wrong HMAC");
            }
        }
예제 #2
0
        public static void TestMethods()
        {
            V1Hmac hmac = new V1Hmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            Assert.That(hmac.Length, Is.EqualTo(V1Hmac.RequiredLength), "The length should always be 16.");
            Assert.That(hmac.GetBytes(), Is.EquivalentTo(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), "Check that GetBytes() returns the expected.");
            Assert.That(hmac, Is.EqualTo(new V1Hmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 })), "Check Equals() override.");
            Assert.That(hmac == new V1Hmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), Is.True, "Check operator== override.");
            Assert.That(hmac != new V1Hmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), Is.False, "Check operator!= override.");

            V1Hmac hmac2 = new V1Hmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            Assert.That(hmac.GetHashCode(), Is.Not.EqualTo(0), "The hash code should not be zero (can be, but it's not in this case).");
            Assert.That(hmac.GetHashCode(), Is.EqualTo(hmac2.GetHashCode()), "The hash code for two different instances with same value should be the same.");

            Assert.That(hmac.Equals(null), Is.False, "An instance is never equal to null.");
            Assert.That(hmac.Equals(new object()), Is.False, "An instance is never equal to another instance of a differing type.");
            V1Hmac hmacSynonym = hmac;

            Assert.That(hmac == hmacSynonym, Is.True, "These should compare equal via reference equality.");
        }