예제 #1
0
        public void SimpleShortHash()
        {
            var expected = Utilities.HexToBinary("9ea31f0aa7ebaa82");
            var actual   = ShortHash.Hash("Adam Caudill", "0123456789123456");

            CollectionAssert.AreEqual(expected, actual);
        }
예제 #2
0
        public void CompareHashTest()
        {
            // Test against known values generated from another libsodium implementation
            string message  = "Charles R. Portwood II";
            var    expected = Convert.FromBase64String("docyE6GyPUA=");
            var    key      = Convert.FromBase64String("4f7fFH5QJtm/7nqinCcRtA==");
            var    hash     = ShortHash.Hash(message, key);

            Assert.AreEqual(8, hash.Length);
            Assert.AreEqual(Convert.ToBase64String(expected), Convert.ToBase64String(hash));
        }
예제 #3
0
        public void GenerateHashTest()
        {
            string message = "Hello, World!";
            var    key     = ShortHash.GenerateKey();
            var    hash    = ShortHash.Hash(message, key);

            Assert.AreEqual(8, hash.Length);

            byte[] byteMessage = System.Text.Encoding.UTF8.GetBytes(message);
            hash = ShortHash.Hash(byteMessage, key);
            Assert.AreEqual(8, hash.Length);
        }
예제 #4
0
        private static byte[] SodiumHash(HashType hash, byte[] buffer)
        {
            switch (hash)
            {
            case HashType.Blake2B:
                return(Blake2B.ComputeHash(buffer));

            case HashType.SipHash24:
                return(ShortHash.Hash(buffer, SipHash24Key));

            case HashType.Sha256:
                return(CryptoHash.Sha256(buffer));

            case HashType.Sha512:
                return(CryptoHash.Sha512(buffer));

            case HashType.Md5:
            case HashType.Sha1:
            case HashType.Sha384:
            default:
                throw new NotSupportedException();
            }
        }