コード例 #1
0
        static void ReadAndVerifyHash(Stream stream, Action <Stream> reader, string hash)
        {
            if (string.IsNullOrEmpty(hash))
            {
                reader(stream);
                return;
            }

            var md5 = MD5.Create();

            // Blob streams throw NSE on Flush()
            using (var hack = new SuppressFlushForStream(stream))
                using (var crypto = new CryptoStream(hack, md5, CryptoStreamMode.Read))
                {
                    reader(crypto);
                }
            var calculated = Convert.ToBase64String(md5.Hash);

            if (calculated != hash)
            {
                throw new StreamingItemIntegrityException("Hash was provided, but it does not match.");
            }
        }
コード例 #2
0
        static void ReadAndVerifyHash(Stream stream, Action<Stream> reader, string hash)
        {
            if (string.IsNullOrEmpty(hash))
            {
                reader(stream);
                return;
            }

            var md5 = MD5.Create();
            // Blob streams throw NSE on Flush()
            using (var hack = new SuppressFlushForStream(stream))
            using (var crypto = new CryptoStream(hack, md5, CryptoStreamMode.Read))
            {
                reader(crypto);
            }
            var calculated = Convert.ToBase64String(md5.Hash);

            if (calculated != hash)
                throw new StreamingItemIntegrityException("Hash was provided, but it does not match.");
        }