Exemplo n.º 1
0
        /// <summary>
        /// Calculate the MD5 of the provided stream
        /// </summary>
        /// <param name="streamToMD5">The stream to calcualte Md5 for</param>
        /// <returns></returns>
        private static string MD5Stream(Stream streamToMD5)
        {
            streamToMD5.Seek(0, SeekOrigin.Begin);

#if WINDOWS_PHONE
            using (var md5 = new DPSBase.MD5Managed())
            {
#else
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
#endif
                return(BitConverter.ToString(md5.ComputeHash(streamToMD5)).Replace("-", ""));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return the MD5 for the specific part of the stream only.
        /// </summary>
        /// <returns></returns>
        public string MD5CheckSum()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                ThreadSafeStream.CopyTo(ms, Start, Length, 8000);

#if WINDOWS_PHONE
                using (var md5 = new DPSBase.MD5Managed())
                {
#else
                using (var md5 = System.Security.Cryptography.MD5.Create())
                {
#endif
                    return(BitConverter.ToString(md5.ComputeHash(ms)).Replace("-", ""));
                }
            }
        }