public void GetString_UpperCase()
        {
            byte[] input  = new byte[] { 0x0A, 0xAC, 0x1F, 0x00 };
            string result = HexConvertor.GetString(input, HexFormat.UpperCase);

            Assert.AreEqual("0AAC1F00", result);
        }
        public void CompareOriginalSha256(string hexKey, string hexLabel, string hexContent, int iterations)
        {
            byte[]      key         = HexConvertor.GetBytes(hexKey);
            byte[]      label       = HexConvertor.GetBytes(hexLabel);
            byte[]      content     = HexConvertor.GetBytes(hexContent);
            Func <HMAC> hmacfactory = () => new HMACSHA256();

            byte[] resultOriginal = new byte[124];
            byte[] resultCustom   = new byte[124];

            SecurityDriven.Inferno.Kdf.SP800_108_Ctr.DeriveKey(hmacfactory,
                                                               key,
                                                               label.Length == 0 ? null : label,
                                                               content.Length == 0 ? null : content,
                                                               resultOriginal,
                                                               (uint)iterations);

            SP800_108.DeriveKey(hmacfactory,
                                key,
                                label.Length == 0 ? Span <byte> .Empty : label,
                                content.Length == 0 ? Span <byte> .Empty : content,
                                resultCustom,
                                (uint)iterations);

            Assert.AreEqual(HexConvertor.GetString(resultOriginal), HexConvertor.GetString(resultCustom));
        }
Example #3
0
        public void Example_ComputeHash()
        {
            byte[] first  = Encoding.ASCII.GetBytes("Hello ");
            byte[] second = Encoding.ASCII.GetBytes("world!");

            using SHA256 sha = SHA256.Create();
            sha.Update(first);
            sha.Update(second);

            byte[] hash   = sha.DoFinal();
            string result = $"SHA256 of 'Hello world!' is {HexConvertor.GetString(hash)}";

            Assert.IsNotNull(result);
        }