Esempio n. 1
0
        static List <Location> GetWalkableAdjacentSquares(int x, int y, string input, string movement)
        {
            MD5Managed md5 = new MD5Managed();

            byte[] hash = md5.ComputeHash(Encoding.ASCII.GetBytes(input + movement));

            List <Location> possibleLocations = new List <Location>();

            if ((((hash[0] >> 4) & 0xf) > 10) && (y > 0))
            {
                possibleLocations.Add(new Location {
                    X = x, Y = y - 1, Movement = movement + "U"
                });
            }
            if (((hash[0] & 0xf) > 10) && (y < 3))
            {
                possibleLocations.Add(new Location {
                    X = x, Y = y + 1, Movement = movement + "D"
                });
            }
            if ((((hash[1] >> 4) & 0xf) > 10) && (x > 0))
            {
                possibleLocations.Add(new Location {
                    X = x - 1, Y = y, Movement = movement + "L"
                });
            }
            if (((hash[1] & 0xf) > 10) && (x < 3))
            {
                possibleLocations.Add(new Location {
                    X = x + 1, Y = y, Movement = movement + "R"
                });
            }

            return(possibleLocations);
        }
Esempio n. 2
0
            public byte[] ComputeMD5Hash(Stream steam)
            {
                MD5Managed md5 = new MD5Managed();

                byte[] hashed = md5.ComputeHash(steam);
                return(hashed);
            }
        public byte[] CreateMD5(byte[] value)
        {
            var md5 = new MD5Managed();

            md5.ComputeHash(value);
            return(md5.Hash);
        }
Esempio n. 4
0
 private string Md5Helper(byte[] buffer)
 {
     using (var md5 = new MD5Managed())
     {
         return(Convert.ToBase64String(md5.ComputeHash(buffer)));
     }
 }
Esempio n. 5
0
 /// <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)
 {
     using (var hash = new MD5Managed())
     {
         return(hash.ComputeHash(input, offset, count));
     }
 }
Esempio n. 6
0
 /// <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)
 {
     using (var hash = new MD5Managed())
     {
         return(hash.ComputeHash(input));
     }
 }
Esempio n. 7
0
        private static string ComputeEncodedMD5FromEncodedString(string base64EncodedString)
        {
            var unencodedValue = Convert.FromBase64String(base64EncodedString);
            var valueMD5       = md5.ComputeHash(unencodedValue);
            var encodedMD5     = Convert.ToBase64String(valueMD5);

            return(encodedMD5);
        }
Esempio n. 8
0
        public static byte[] ComputeMD5(byte[] data)
        {
#if WINDOWS_PHONE
            var md5 = new MD5Managed();
            return(md5.ComputeHash(data));
#elif WIN_RT
            var md5 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
            return(md5.HashData(data.AsBuffer()).ToArray());
#endif
        }
        /// <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
        }
        /// <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 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(ExceptionHelper.ThrowNotSupported <byte[]>());
#else
            using (var hash = new MD5Managed())
            {
                return(hash.ComputeHash(input, offset, count));
            }
#endif
        }
Esempio n. 12
0
        /// <summary>
        /// Generates md5 digest.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static string DoDigest(string parameters)
        {
            MD5Managed md5 = new MD5Managed();
            md5.Initialize();
            byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(parameters));

            int len = hash.Length;
            StringBuilder sb = new StringBuilder(len << 1);
            for (int i = 0; i < len; i++)
            {
                sb.Append(((hash[i] & 0xf0) >> 4).ToString("X"));
                sb.Append((hash[i] & 0x0f).ToString("X"));
            }

            return sb.ToString();
        }
Esempio n. 13
0
        private string CalculateMD5Hash(string input)
        {
            // step 1, calculate MD5 hash from input
            MD5Managed md5 = new MD5Managed();

            byte[] inputBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(input);
            byte[] hash       = md5.ComputeHash(inputBytes);

            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return(sb.ToString());
        }
Esempio n. 14
0
        /// <summary>
        /// Generates md5 digest.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static string DoDigest(string parameters)
        {
            MD5Managed md5 = new MD5Managed();

            md5.Initialize();
            byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(parameters));

            int           len = hash.Length;
            StringBuilder sb  = new StringBuilder(len << 1);

            for (int i = 0; i < len; i++)
            {
                sb.Append(((hash[i] & 0xf0) >> 4).ToString("X"));
                sb.Append((hash[i] & 0x0f).ToString("X"));
            }

            return(sb.ToString());
        }
Esempio n. 15
0
        private static string GetHash(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            var text = value
                       .Trim()
                       .ToLower();

            using var md5 = new MD5Managed();
            byte[] buffer = Encoding.ASCII.GetBytes(text);
            byte[] bytes  = md5.ComputeHash(buffer);

            var hash = BitConverter
                       .ToString(bytes)
                       .Replace("-", "")
                       .ToLower();

            return(hash);
        }
Esempio n. 16
0
        static byte[] GenerateHash(byte[] toHash)
        {
            MD5Managed md5 = new MD5Managed();

            return(md5.ComputeHash(toHash));
        }
Esempio n. 17
0
 public byte[] ComputeHash(byte[] buffer)
 {
     return(_algorithm.ComputeHash(buffer));
 }
Esempio n. 18
0
        static void Test2(int count)
        {
            byte[] bytes = new byte[count];

            for (int idx = 0; idx < count; idx += 16)
                Array.Copy(Guid.NewGuid().ToByteArray(), 0, bytes, idx, Math.Min(16, count - idx));

            MD5 md5dotNet = new MD5CryptoServiceProvider();
            md5dotNet.Initialize();
            MD5Managed md5m = new MD5Managed();
            md5m.Initialize();

            byte[] result1 = md5dotNet.ComputeHash(bytes);
            byte[] result2 = md5m.ComputeHash(bytes);

            if (!CompareBytes(result1, result2))
            {
                count.GetType();
                //throw new Exception("Bug in MD5Managed...");
            }
        }
Esempio n. 19
0
 public byte[] ComputeMD5Hash(Stream steam)
 {
     MD5Managed md5 = new MD5Managed();
     byte[] hashed = md5.ComputeHash(steam);
     return hashed;
 }
Esempio n. 20
0
        public AkamaiCdnToken(string inUrl, long inWindow, string salt, string extract, long time, string inParam)
        {
            if (string.IsNullOrEmpty(inUrl))
            {
                throw new TokenException("URL is empty or null");
            }

            if (inWindow < 0)
            {
                throw new TokenException("Window is negative");
            }

            if (string.IsNullOrEmpty(salt))
            {
                throw new TokenException("Salt is empty or null");
            }

            this.url   = inUrl;
            this.param = inParam;
            extract    = string.IsNullOrEmpty(extract) ? null : extract;

            if (time <= 0)
            {
                time = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            }

            if (string.IsNullOrEmpty(this.param))
            {
                this.param = "__gda__";
            }

            if (this.param.Length < 5 || this.param.Length > 12)
            {
                throw new TokenException("Parameter must be between 5 and 12 characters in length");
            }

            this.expires = time + inWindow;

            var expBytes = BitConverter.GetBytes((int)(time + inWindow));

            /*
             * The token generated has this structure:
             *  MD5(salt|MD5(Url|extract|salt))
             */
            var sb = new StringBuilder();

            sb.Append(this.url);
            sb.Append(extract);
            sb.Append(salt);

            byte[] dataBytes = Encoding.UTF8.GetBytes(sb.ToString());

            byte[] buffer1 = new byte[expBytes.Length + sb.Length];

            Array.Copy(expBytes, buffer1, expBytes.Length);
            Array.Copy(dataBytes, 0, buffer1, expBytes.Length, dataBytes.Length);

            MD5Managed hashComputer = new MD5Managed();

            byte[] digest1 = hashComputer.ComputeHash(buffer1);

            byte[] saltBytes = Encoding.UTF8.GetBytes(salt);

            byte[] binaryString = new byte[saltBytes.Length + digest1.Length];
            Array.Copy(saltBytes, binaryString, saltBytes.Length);
            Array.Copy(digest1, 0, binaryString, saltBytes.Length, digest1.Length);

            byte[] binaryToken = hashComputer.ComputeHash(binaryString);

            // Generate a token string from the byte array
            var tokenString = string.Concat(binaryToken.Select(b => string.Format("{0:x2}", b)));

            this.token = tokenString;
        }