// Copyright 2018 RED Software, LLC. All Rights Reserved.

using System.Text;

namespace IgniteEngine
{
    public static class StringExtensions
    {
        /// <summary>
        /// Returns an MD5 hash of the provided string.
        /// </summary>
        /// <param name="input">The string to hash.</param>
        public static string MD5(this string input)
        {
            var md5 = System.Security.Cryptography.MD5.Create();
            var inputBuffer = Encoding.ASCII.GetBytes(input);
            var hash = md5.ComputeHash(inputBuffer);
            var stringBuilder = new StringBuilder();

            foreach (var b in hash)
            {
                stringBuilder.Append(b.ToString("x2"));
            }

            return stringBuilder.ToString();
        }
    }
}
