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

            Assert.AreEqual("0AAC1F00", result);
        }
コード例 #2
0
        public void GetBytes(string input)
        {
            byte[] excepted = new byte[] { 0x0A, 0xAC, 0x1F, 0x00 };

            byte[] result = HexConvertor.GetBytes(input);
            CollectionAssert.AreEquivalent(excepted, result);
        }
コード例 #3
0
        public void DeriveKeyWithString()
        {
            byte[] key            = HexConvertor.GetBytes("1f5942ea0ab514227e339d14743b1df7707a868483725d6166d850d57cd33420");
            byte[] resultOriginal = new byte[124];

            SP800_108.DeriveKey("HMACSHA256", key, derivedOutput: resultOriginal);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        public void TryGetBytes(string input)
        {
            byte[]      excepted = new byte[] { 0x0A, 0xAC, 0x1F, 0x00 };
            Span <byte> result   = new byte[12];

            Assert.IsTrue(HexConvertor.TryGetBytes(input, result, out int witeBytes));

            CollectionAssert.AreEquivalent(excepted, result.Slice(0, witeBytes).ToArray());
        }
コード例 #6
0
        public void TryGetString_UpperCase()
        {
            byte[]      input  = new byte[] { 0x0A, 0xAC, 0x1F, 0x00 };
            Span <char> output = new char[input.Length * 2];

            Assert.IsTrue(HexConvertor.TryGetString(input, HexFormat.UpperCase, output, out int writeChars));

            Assert.AreEqual("0AAC1F00", output.ToString());
            Assert.AreEqual(input.Length * 2, writeChars);
        }
コード例 #7
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);
        }
コード例 #8
0
 public Pkcs9IdSigningPolicy(string policyOid, HashAlgorithmName algorithmNameForPolicy, string policyHexHashValue)
     : base(Pkcs7Oids.IdSigningPolicy, CreateRawAsn1(policyOid, algorithmNameForPolicy, HexConvertor.GetBytes(policyHexHashValue)))
 {
     this.PolicyOid = policyOid;
 }
コード例 #9
0
 public void GetBytes_secure(string input)
 {
     Assert.ThrowsException <ArgumentException>(() => HexConvertor.GetBytes(input));
 }