Exemplo n.º 1
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 NETFX_CORE
                    var alg        = Windows.Security.Cryptography.Core.HashAlgorithmProvider.OpenAlgorithm(Windows.Security.Cryptography.Core.HashAlgorithmNames.Md5);
                    var buffer     = (new Windows.Storage.Streams.DataReader(ms.AsInputStream())).ReadBuffer((uint)ms.Length);
                    var hashedData = alg.HashData(buffer);
                    return(Windows.Security.Cryptography.CryptographicBuffer.EncodeToHexString(hashedData).Replace("-", ""));
#else
#if WINDOWS_PHONE
                    using (var md5 = new Tools.MD5Managed())
                    {
#else
                    using (var md5 = System.Security.Cryptography.MD5.Create())
                    {
#endif
                        return(BitConverter.ToString(md5.ComputeHash(ms)).Replace("-", ""));
                    }
#endif
                }
            }