Exemplo n.º 1
0
 public MD5CalculatingStream(System.IO.Stream basestream)
     : base(basestream)
 {
     m_hash = (System.Security.Cryptography.MD5)System.Security.Cryptography.HashAlgorithm.Create("MD5");
     m_hash.Initialize();
     m_hashbuffer = new byte[m_hash.InputBlockSize];
 }
Exemplo n.º 2
0
 public MD5CalculatingStream(System.IO.Stream basestream)
     : base(basestream)
 {
     m_hash = (System.Security.Cryptography.MD5)System.Security.Cryptography.HashAlgorithm.Create("MD5");
     m_hash.Initialize();
     m_hashbuffer = new byte[m_hash.InputBlockSize];
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get a cached or create a Normal Map from a Texture
        /// </summary>
        /// <param name="texture"></param>
        /// <returns></returns>
        internal static Texture2D GetNormalMap(Texture2D texture)
        {
            if (texture == null || string.IsNullOrEmpty(texture.name))
            {
                Log.Error("Could not get NormalTexture for empty name or Texture");
                return(null);
            }

            System.Security.Cryptography.MD5 md5Hash = System.Security.Cryptography.MD5.Create();
            md5Hash.Initialize();
            byte[] crypto     = md5Hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(texture.name));
            string normalHash = string.Empty;

            foreach (byte theByte in crypto)
            {
                normalHash += theByte.ToString("x2");
            }

            string storagePath = KSPUtil.ApplicationRootPath + "PluginData/KerbalKonstructs/Normals/";

            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }

            string filename = storagePath + normalHash + ".png";

            Texture2D normalMap;

            // first check if we loaded the map before:
            if (normalMaps.ContainsKey(normalHash))
            {
                //Log.Normal("returning Cached normalMap");
                return(normalMaps[normalHash]);
            }
            else
            {
                if (!File.Exists(filename))
                {
                    CreateNormalFromTex(texture, filename);
                }
                if (File.Exists(filename))
                {
                    normalMap = LoadNormalFromFile(filename, texture.width, texture.height);
                    normalMaps.Add(normalHash, normalMap);
                    //Log.Normal("returning normalMap from File");
                    return(normalMap);
                }
            }
            // here you should never end
            Log.Error("Something went wrong for: " + texture.name);
            Log.Error("Should be chached here: " + filename);

            return(null);
        }
Exemplo n.º 4
0
        public static string MD5(string input)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            md5.Initialize();
            byte[]        inputBytes = StringToByteArray(input);
            byte[]        hash       = md5.ComputeHash(inputBytes);
            StringBuilder sb         = new StringBuilder(32);

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return(sb.ToString());
        }
Exemplo n.º 5
0
        public static ulong GetHashFromString(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(0);                         // invalid hash
            }
            byte[] bytes;

            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
            {
                md5.Initialize();
                md5.ComputeHash(Encoding.UTF8.GetBytes(s));
                bytes = md5.Hash;
                return((ulong)BitConverter.ToUInt64(bytes, 0));
            }
        }
Exemplo n.º 6
0
        public override ClientWardenModule GetModuleForClient()
        {
            ClientWardenModule mod = new ClientWardenModule();

            uint length = (uint)WardenModuleWin.Module.Length;

            // data assign
            mod.CompressedSize = length;
            mod.CompressedData = WardenModuleWin.Module;
            mod.Key            = WardenModuleWin.ModuleKey;

            // md5 hash
            System.Security.Cryptography.MD5 ctx = System.Security.Cryptography.MD5.Create();
            ctx.Initialize();
            ctx.TransformBlock(mod.CompressedData, 0, mod.CompressedData.Length, mod.CompressedData, 0);
            ctx.TransformBlock(mod.Id, 0, mod.Id.Length, mod.Id, 0);

            return(mod);
        }
Exemplo n.º 7
0
        private static String GenerateBound()
        {
            StringBuilder stringBuilder = new StringBuilder();
            StringBuilder stringHash    = new StringBuilder();
            Random        random        = new Random((int)DateTime.UtcNow.Ticks);

            for (int x = 0; x < 32; x++)
            {
                stringBuilder.Append(random.Next());
            }
            byte[] bs = Encoding.UTF8.GetBytes(stringBuilder.ToString());
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            md5.Initialize();
            byte[] hash = md5.ComputeHash(bs, 0, bs.Length);
            for (int i = 0; i < hash.Length; i++)
            {
                stringHash.Append(hash[i].ToString("x2"));
            }

            return(stringHash.ToString());
        }
Exemplo n.º 8
0
 public static byte[] MD5buf(byte[] buf, int length)
 {
     System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
     md5.Initialize();
     return(md5.ComputeHash(buf, 0, length));
 }