Example #1
0
        public void WriterHash()
        {
            using var hw = new KzWriterHash();
            var empty = hw.GetHashFinal().ToHex();

            Assert.Equal("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456", empty);

            hw.Add("abc".ASCIIToBytes());
            var abc = hw.GetHashFinal().ToHex();

            Assert.Equal("4f8b42c22dd3729b519ba6f68d2da7cc5b2d606d05daed5ad5128cc03e6c6358", abc);

            hw.Add("de188941a3375d3a8a061e67576e926d".HexToBytes());
            var rc4_16 = hw.GetHashFinal().ToHex();

            Assert.Equal("2182d3fe9882fd597d25daf6a85e3a574e5a9861dbc75c13ce3f47fe98572246", rc4_16);

            hw.Add("56f47c020000000008516365655252516a".HexToBytes());
            var idx2 = hw.GetHashFinal().ToString();

            Assert.Equal("1e05cef9f4a9bbf62f9293b5466087b467ed3326d1f03af72f2d4ff2cf66797a", idx2);
        }
Example #2
0
        public void Partial()
        {
            var       data = "Some random stuff for testing purposes.".ASCIIToBytes();
            KzUInt256 h1;
            KzUInt256 h2;

            KzUInt256 refonce;
            KzUInt256 reftwice;

            using (var alg = new SHA256Managed()) {
                alg.TransformFinalBlock(data, 0, data.Length);
                refonce = h1 = alg.Hash.ToKzUInt256();
                alg.TransformFinalBlock(data, 0, data.Length);
                h2 = alg.Hash.ToKzUInt256();
                Assert.Equal(h1, h2);

                alg.TransformFinalBlock(h1.ToBytes(), 0, 32);
                reftwice = alg.Hash.ToKzUInt256();
            }

            using (var alg = new SHA256Managed()) {
                alg.TransformBlock(data, 0, data.Length - 12, null, 0);
                alg.TransformFinalBlock(data, data.Length - 12, 12);
                h1 = alg.Hash.ToKzUInt256();
                Assert.Equal(refonce, h1);
            }

            using (var alg = new SHA256Managed()) {
                alg.TransformBlock(data, 0, data.Length, null, 0);
                alg.TransformFinalBlock(data, 0, 0);
                h1 = alg.Hash.ToKzUInt256();
                Assert.Equal(refonce, h1);
            }

            using (var hw = new KzWriterHash()) {
                hw.Add(data[..12]);