public static byte[] Blake2(FileStream fileStream, byte[] key)
 {
     using (var blake2 = new GenericHash.GenericHashAlgorithm(key, Constants.HashLength))
     {
         return(blake2.ComputeHash(fileStream));
     }
 }
Exemple #2
0
        public void ComputeHashFromBytes()
        {
            var expected   = Utilities.HexToBinary("8866267f985204ae511980704ac85ec4936ee535c37541f342976b2cb3ac62fd");
            var hashStream = new GenericHash.GenericHashAlgorithm("This is a test key", 32);
            var actual     = hashStream.ComputeHash(Encoding.UTF8.GetBytes("Adam Caudill"));

            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void ComputeHashFromNullStream()
        {
            var expected   = Utilities.HexToBinary("4afd15412c1b940d7cffc9049b9ed413cbaeb626aca2a70c2afbeea7a85bdf8e");
            var stream     = Stream.Null;
            var hashStream = new GenericHash.GenericHashAlgorithm("This is a test key", 32);
            var actual     = hashStream.ComputeHash(stream);

            CollectionAssert.AreEqual(expected, actual);
        }
        public static byte[] Hash(byte[] payload, byte[] nonce)
        {
            if (nonce == null)
            {
                nonce = new byte[24];
                using (var random = new RNGCryptoServiceProvider())
                    random.GetBytes(nonce);
            }

            var hashAlgorithm = new GenericHash.GenericHashAlgorithm(nonce, 24);

            return(hashAlgorithm.ComputeHash(payload));
        }
Exemple #5
0
        public static Tuple <byte[], byte[]> GenerateClientSessionKeys(KeyPair clientKeys, byte[] serverPublicKey)
        {
            var junk         = new byte[Math.Max(crypto_kx_SESSIONKEYBYTES, clientKeys.PublicKey.Length)];
            var clientSecret = ScalarMult.Mult(clientKeys.PrivateKey, serverPublicKey);

            using (var clientHash = new GenericHash.GenericHashAlgorithm((byte[])null, 2 * crypto_kx_SESSIONKEYBYTES))
            {
                clientHash.Initialize();
                clientHash.TransformBlock(clientSecret, 0, clientSecret.Length, junk, 0);
                clientHash.TransformBlock(clientKeys.PublicKey, 0, clientSecret.Length, junk, 0);
                clientHash.TransformFinalBlock(serverPublicKey, 0, clientSecret.Length);
                var rx = clientHash.Hash.Take(crypto_kx_SESSIONKEYBYTES);
                var tx = clientHash.Hash.Skip(crypto_kx_SESSIONKEYBYTES);
                return(Tuple.Create(rx.ToArray(), tx.ToArray()));
            }
        }
Exemple #6
0
 public static byte[] Hash(FileStream fileStream)
 {
     using var blake2 = new GenericHash.GenericHashAlgorithm(key: (byte[])null, Constants.BLAKE2Length);
     return(blake2.ComputeHash(fileStream));
 }