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 GetBytes(string input) { byte[] excepted = new byte[] { 0x0A, 0xAC, 0x1F, 0x00 }; byte[] result = HexConvertor.GetBytes(input); CollectionAssert.AreEquivalent(excepted, result); }
public void DeriveKeyWithString() { byte[] key = HexConvertor.GetBytes("1f5942ea0ab514227e339d14743b1df7707a868483725d6166d850d57cd33420"); byte[] resultOriginal = new byte[124]; SP800_108.DeriveKey("HMACSHA256", key, derivedOutput: resultOriginal); }
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)); }
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()); }
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); }
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); }
public Pkcs9IdSigningPolicy(string policyOid, HashAlgorithmName algorithmNameForPolicy, string policyHexHashValue) : base(Pkcs7Oids.IdSigningPolicy, CreateRawAsn1(policyOid, algorithmNameForPolicy, HexConvertor.GetBytes(policyHexHashValue))) { this.PolicyOid = policyOid; }
public void GetBytes_secure(string input) { Assert.ThrowsException <ArgumentException>(() => HexConvertor.GetBytes(input)); }