Beispiel #1
0
        public string ComputeMD5()
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            byte[] hash = null;
            if (NumberOfFrames == 1)
            {
                byte[] frame = GetFrameDataU8(0);
                hash = md5.ComputeHash(frame);
            }
            else
            {
                for (int i = 0; i < NumberOfFrames; i++)
                {
                    byte[] frame = GetFrameDataU8(i);

                    if (i < (NumberOfFrames - 1))
                    {
                        md5.TransformBlock(frame, 0, frame.Length, frame, 0);
                    }
                    else
                    {
                        md5.TransformFinalBlock(frame, 0, frame.Length);
                    }
                }
                hash = md5.Hash;
            }

            return(BitConverter.ToString(hash).Replace("-", ""));
        }
 private string CalculateMd5Hash(string input)
 {
     var inputBytes = Encoding.UTF8.GetBytes(input);
     var hash = new MD5Managed().ComputeHash(inputBytes);
     var sb = new StringBuilder();
     foreach (var b in hash)
         sb.Append(b.ToString("x2"));
     return sb.ToString();
 }
        /// <summary>
        /// Convert to MD5 hash string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ToMD5Hash(this string value)
        {
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(value);
            MD5Managed md5 = new MD5Managed();
            byte[] hash = md5.ComputeHash(bs);

            StringBuilder sb = new StringBuilder();
            foreach (byte b in bs)
            {
                sb.Append(b.ToString("x2").ToLower());
            }

            return sb.ToString();
        }
Beispiel #4
0
 /// <summary>
 /// Gets MD5 hash of a byte array
 /// </summary>
 /// <param name="buffer">Byte array</param>
 /// <returns>MD5 hash as string</returns>
 public static string MD5(byte[] buffer)
 {
     MD5 md5 = new MD5CryptoServiceProvider();
     return BitConverter.ToString(md5.ComputeHash(buffer)).Replace("-", "");
 }
 public byte[] CreateMD5(byte[] value)
 {
     var md5 = new MD5Managed();
     md5.ComputeHash(value);
     return md5.Hash;
 }
Beispiel #6
0
		static void Compute_NTLMv2_Session (string password, byte[] challenge,
		                                    out byte[] lm, out byte[] ntlm)
		{
			var nonce = new byte [8];
			var rng = RandomNumberGenerator.Create ();
			rng.GetBytes (nonce);

			var sessionNonce = new byte [challenge.Length + 8];
			challenge.CopyTo (sessionNonce, 0);
			nonce.CopyTo (sessionNonce, challenge.Length);

			lm = new byte [24];
			nonce.CopyTo (lm, 0);

#if MOONLIGHT
			MD5Managed md5 = new MD5Managed ();
#else
			MD5 md5 = MD5.Create ();
#endif
			
			var hash = md5.ComputeHash (sessionNonce);
			var newChallenge = new byte [8];
			Array.Copy (hash, newChallenge, 8);

			ntlm = Compute_NTLM (password, newChallenge);

			// clean up
			Array.Clear (nonce, 0, nonce.Length);
			Array.Clear (sessionNonce, 0, sessionNonce.Length);
			Array.Clear (newChallenge, 0, newChallenge.Length);
			Array.Clear (hash, 0, hash.Length);
		}
        /// <summary>
        /// Computes the MD5 hash for the current byte array.
        /// </summary>
        /// <param name="input">The input <see cref="Stream"/> to compute the hash code for.</param>
        /// <returns>The computed hash code.</returns>
        public static byte[] ComputeMD5Hash(this Stream input)
        {
#if PORTABLE
            return null;
#else
            using (var hash = new MD5Managed())
            {
                return hash.ComputeHash(input);
            }
#endif
        }
Beispiel #8
0
        /// <summary>
        /// Gets MD5 hash of a byte array
        /// </summary>
        /// <param name="buffer">Byte array</param>
        /// <returns>MD5 hash as string</returns>
        public static string MD5(byte[] buffer)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            return(BitConverter.ToString(md5.ComputeHash(buffer)).Replace("-", ""));
        }
        /// <summary>
        /// Computes the MD5 hash for the current byte array using the managed library.
        /// </summary>
        /// <param name="input">An array of 8-bit unsigned integers.</param>
        /// <param name="offset">The offset into the byte array from which to begin using data.</param>
        /// <param name="count">The number of bytes in the array to use as data.</param>
        /// <returns>The computed hash code.</returns>
        public static byte[] ComputeMD5Hash(this byte[] input, int offset, int count)
        {
#if PORTABLE
            return null;
#else
            using (var hash = new MD5Managed())
            {
                return hash.ComputeHash(input, offset, count);
            }
#endif
        }
 /// <summary>
 /// Computes the <see cref="MD5"/> hash for the current byte array using the managed library.
 /// </summary>
 /// <param name="input">An array of 8-bit unsigned integers.</param>
 /// <param name="offset">The offset into the byte array from which to begin using data.</param>
 /// <param name="count">The number of bytes in the array to use as data.</param>
 /// <returns>The computed hash code.</returns>
 public static byte[] ComputeMD5Hash(this byte[] input, int offset, int count)
 {
     using (var hash = new MD5Managed())
     {
         return hash.ComputeHash(input, offset, count);
     }
 }