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 byte[] Hash(FileStream fileStream)
 {
     using var blake2 = new GenericHash.GenericHashAlgorithm(key: (byte[])null, Constants.BLAKE2Length);
     return(blake2.ComputeHash(fileStream));
 }