Пример #1
0
        /// <summary>
        /// Computes the SHA1-checksum of a given buffer.
        /// </summary>
        /// <param name="buffer">The buffer to compute its checksum from. Must not be null.</param>
        /// <returns>The SHA1-checksum of the given buffer as a string.</returns>
        public static string ComputeSHA1(byte[] buffer)
        {
            Assertions.AssertNotNull(buffer, "buffer");

            using (SHA1 md5 = SHA1.Create())
            {
                byte[] result = md5.ComputeHash(buffer);

                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    strBuilder.Append(result[i].ToString("x2"));
                }

                return(strBuilder.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Computes the MD5-checksum of a given stream.
        /// </summary>
        /// <param name="stream">The stream to compute its checksum from. Must not be null.</param>
        /// <returns>The MD5-checksum of the given stream as a string.</returns>
        public static string ComputeMD5(Stream stream)
        {
            Assertions.AssertNotNull(stream, "stream");

            using (MD5 md5 = MD5.Create())
            {
                byte[] result = md5.ComputeHash(stream);

                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    strBuilder.Append(result[i].ToString("x2"));
                }

                return(strBuilder.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// Performs a check against a <see cref="XDocument"/> to see if the schema is valid.
        /// </summary>
        /// <param name="doc">The <see cref="XDocument"/> to check its schema.</param>
        /// <param name="schema">The schema to use for validation.</param>
        /// <returns>A boolean value indicating whether or not the schema of the given <see cref="XDocument"/> is valid, or not.</returns>
        public static bool IsXmlValid(this XDocument doc, string schema)
        {
            Assertions.AssertNotNull(doc, "doc");
            Assertions.AssertNotEmpty(schema, "schema");

            try
            {
                ValidateXml(doc, schema);
            }
            catch (XmlSchemaException)
            {
                return(false);
            }
            catch (XmlException)
            {
                return(false);
            }
            return(true);
        }