public static string Sum(SrvsFile m) { if (!srvmd5memo.ContainsKey(m.Name)) { Sum(m.Request); Sum(m.Response); string hashablereq = PrepareToHash(m.Request); string hashableres = PrepareToHash(m.Response); if (hashablereq == null || hashableres == null) { return(null); } byte[] req = Encoding.ASCII.GetBytes(hashablereq); byte[] res = Encoding.ASCII.GetBytes(hashableres); StringBuilder sb = new StringBuilder(); System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); md5.TransformBlock(req, 0, req.Length, req, 0); md5.TransformFinalBlock(res, 0, res.Length); for (int i = 0; i < md5.Hash.Length; i++) { sb.AppendFormat("{0:x2}", md5.Hash[i]); } srvmd5memo.Add(m.Name, sb.ToString()); } return(srvmd5memo[m.Name]); }
public byte[] GetFinalHash() { if (m_finalHash == null) { m_hash.TransformFinalBlock(m_hashbuffer, 0, m_hashbufferLength); m_finalHash = m_hash.Hash; } return(m_finalHash); }
public static string CalculateMD5(Stream stream, int bufferSize) { byte[] _emptyBuffer = new byte[0]; System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create(); byte[] buffer = new byte[bufferSize]; int readBytes; while ((readBytes = stream.Read(buffer, 0, bufferSize)) > 0) { md5Hasher.TransformBlock(buffer, 0, readBytes, buffer, 0); } md5Hasher.TransformFinalBlock(_emptyBuffer, 0, 0); return(CUtils.ToHexString(md5Hasher.Hash)); }
public ImagePixelLock(Bitmap inSource, System.Drawing.Rectangle inLockRegion, Boolean inCreateCopy) { if (inSource.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { throw new ArgumentException("Given bitmap has an unsupported pixel format."); } IsCopy = inCreateCopy; if (inCreateCopy) { bitmap = (Bitmap)inSource.Clone(); } else { bitmap = inSource; } data = bitmap.LockBits(inLockRegion, ImageLockMode.ReadWrite, inSource.PixelFormat); Pixels = (int *)data.Scan0.ToPointer(); // compute checksum from pixeldata System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); int *ptr = (int *)data.Scan0.ToPointer(); for (int i = 0, byteCount = Width * Height * 4; i < byteCount; i += buffer.Length) { int count = Math.Min(buffer.Length, byteCount - i); System.Runtime.InteropServices.Marshal.Copy((IntPtr)ptr, buffer, 0, count); md5.TransformBlock(buffer, 0, count, tmpBuffer, 0); ptr += count / 4; } md5.TransformFinalBlock(new byte[0], 0, 0); byte[] checksum = md5.Hash; for (int i = 0; i < 8; i++) { Checksum |= (((Int64)checksum[i]) << (i * 8)); } }
public void UpdateImage(string inPath) { if (!System.IO.File.Exists(inPath) || !inPath.EndsWith(".png")) { return; } Texture2D Tex2D; byte[] FileData; FileData = System.IO.File.ReadAllBytes(inPath); Tex2D = new Texture2D(2, 2); // Create new "empty" texture if (!Tex2D.LoadImage(FileData)) // Load the imagedata into the texture (size is set automatically) { return; // If data = readable -> return texture } System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); byte[] pathBytes = System.Text.Encoding.UTF8.GetBytes(inPath); md5.TransformBlock(pathBytes, 0, pathBytes.Length, pathBytes, 0); byte[] contentBytes = System.IO.File.ReadAllBytes(inPath); md5.TransformFinalBlock(contentBytes, 0, contentBytes.Length); myTextureData = new TextureData(Tex2D, inPath, System.BitConverter.ToString(md5.Hash).Replace("-", "").ToLower()); float ratio = myTextureData.myTexture.width / myTextureData.myTexture.height; if (80 / 60 > ratio) { myImg.rectTransform.sizeDelta = new Vector2(30 * ratio, 30); } else { myImg.rectTransform.sizeDelta = new Vector2(40, 40 / ratio); } ImgNameText.text = System.IO.Path.GetFileName(inPath); myImg.sprite = Sprite.Create(myTextureData.myTexture, new Rect(0, 0, myTextureData.myTexture.width, myTextureData.myTexture.height), new Vector2(0.5f, 0.5f)); }
public static string Sum(params byte[][] data) { StringBuilder sb = new StringBuilder(); System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); if (data.Length > 0) { for (int i = 0; i < data.Length - 1; i++) { md5.TransformBlock(data[i], 0, data[i].Length, data[0], 0); } md5.TransformFinalBlock(data[data.Length - 1], 0, data[data.Length - 1].Length); } for (int i = 0; i < md5.Hash.Length; i++) { sb.AppendFormat("{0:x2}", md5.Hash[i]); } return(sb.ToString()); }