/// <summary>
        /// Adds a thumbnail
        /// </summary>
        /// <param name="img">The image to create the thumbnail from</param>
        /// <returns>The MD5 of the thumbnail</returns>
        public static string Add(Stream img, string origPath)
        {
            img.Seek(0, SeekOrigin.Begin);

            string md5Hash;

            using (var origIMG = Image.FromStream(img)) {
                double ratio = Math.Min((double)ThumbnailWidth / origIMG.Width, (double)ThumbnailHeight / origIMG.Height);

                using (var newBMP = new Bitmap((int)Math.Ceiling(origIMG.Width * ratio), (int)Math.Ceiling(origIMG.Height * ratio))) {
                    using (var graph = Graphics.FromImage(newBMP)) {
                        graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                        graph.DrawImage(origIMG, 0, 0, (float)Math.Ceiling(origIMG.Width * ratio), (float)Math.Ceiling(origIMG.Height * ratio));
                        graph.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);

                        using (var stream = new MemoryStream(1024 * 1024)) {
                            newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            stream.Flush();
                            byte [] bytes = stream.ToArray();

                            using (var hasher = new System.Security.Cryptography.MD5Cng())
                                md5Hash = BitConverter.ToString(hasher.ComputeHash(bytes)).Replace("-", "");

                            File.WriteAllBytes(Path.Combine(Program.Options.ThumbsPath, md5Hash), bytes);
                            thumbs.SetEntry(md5Hash, origPath);

                            bytes = null;
                        }
                    }
                }
            }

            return(md5Hash);
        }
示例#2
0
        //md5加密算法
        public static string strToMd5(string sequence)
        {
            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5Cng();
            byte[] bytResult = md5.ComputeHash(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(sequence));

            //转换成字符串,32位
            string strResult = BitConverter.ToString(bytResult).Replace("-", "");

            return(strResult);
        }
示例#3
0
文件: Pepsin.cs 项目: The-Mr-T/Pepsin
        public Pepsin(System.Net.HttpListener listener)
        {
            m_listener = listener;

            m_nonces     = new Dictionary <string, string>();
            m_realms     = new Dictionary <string, string>();
            m_userRealms = new Dictionary <string, string[]>();
            m_users      = new Dictionary <string, Password>();

            m_MD5Encoder = new System.Security.Cryptography.MD5Cng();
        }
 internal static byte[] CalcMD5(string SpecFunc, string SpecName, string SpecDev, int RevMaj, int RevMin)
 {
     byte[] Md5Buffer = new byte[62];
     System.Security.Cryptography.MD5Cng Calc = new System.Security.Cryptography.MD5Cng();
     AddToBuffer(Md5Buffer, 0, 20, AllignTo20(SpecFunc));
     AddToBuffer(Md5Buffer, 20, 20, AllignTo20(SpecName));
     AddToBuffer(Md5Buffer, 40, 20, AllignTo20(SpecDev));
     Md5Buffer[60] = (byte)(RevMaj + 0x30);
     Md5Buffer[61] = (byte)(RevMin + 0x30);
     return Calc.ComputeHash(Md5Buffer,0, 62);
 }
示例#5
0
        public void DrawButton(RectangleF area, Graphics g, bool selected, Guid value)
        {
            float size   = area.Height - 4;
            float imageX = area.Width - area.Height + 2;

            Bitmap[] images = new[] { JONAS, ALI, DANIEL, JUAN };
            System.Security.Cryptography.MD5Cng hash = new System.Security.Cryptography.MD5Cng();
            Bitmap image = images[hash.ComputeHash(value.ToByteArray())[0] & 3];

            g.DrawImage(image, RectangleF.FromLTRB(area.Left + imageX, area.Top + 2, area.Right - 2, area.Bottom - 2));
            TextRenderer.DrawText(g, m_parameter.GetName(value), Font, new Point((int)area.X + 2, (int)area.Y + ((int)area.Height - Font.Height) / 2), Color.White);
        }
示例#6
0
        public static String Md5(String ch)
        {
            using (System.Security.Cryptography.MD5 sha1 = new System.Security.Cryptography.MD5Cng())
            {
                ASCIIEncoding asen = new ASCIIEncoding();
                var hash = sha1.ComputeHash(asen.GetBytes(ch));
                var s = new StringBuilder();
                foreach (byte b in hash)
                    s.Append(b.ToString("x2").ToLower());

                return s.ToString() ;
            }
        }