public void SimpleShortHash() { var expected = Utilities.HexToBinary("9ea31f0aa7ebaa82"); var actual = ShortHash.Hash("Adam Caudill", "0123456789123456"); CollectionAssert.AreEqual(expected, actual); }
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)); }
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); }
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(); } }